CA20304-MAD - Lab (SSV) - 12 12 22
CA20304-MAD - Lab (SSV) - 12 12 22
CA20304-MAD - Lab (SSV) - 12 12 22
Date :
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
<CheckBox
android:id="@+id/c1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:checked="false"
android:padding="10dp"
android:text="Under Graduate" />
<CheckBox
android:id="@+id/c2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:layout_centerHorizontal="true"
android:padding="10dp"
android:text="Post Graduate" />
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center_horizontal" />
<EditText
android:id="@+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
MainActivity.java
package com.example.admin.check2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;
public class MainActivity extends AppCompatActivity
{
CheckBox cc1,cc2;
TextView tt1;
EditText ee1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cc1=(CheckBox)findViewById(R.id.c1);
cc2=(CheckBox)findViewById(R.id.c2);
tt1=(TextView)findViewById(R.id.t1);
ee1=(EditText)findViewById(R.id.e1);
cc1.setOnCheckedChangeListener(new s());
cc2.setOnCheckedChangeListener(new s());
}
class s implements CompoundButton.OnCheckedChangeListener
{
public void onCheckedChanged(CompoundButton button, boolean isChecked)
{
if(cc1.isChecked())
{ ee1.setText("Under Graduate"); }
if(cc2.isChecked())
{ ee1.setText("Post Graduate"); } } } }
OUTPUT :
Ex.No.1(b). Develop an application that uses GUI components, RadioButton Demo.
Date :
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.admin.radioexam1.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:layout_marginLeft="100dp"
android:textSize="18dp"
android:text="Select Your Course"
android:textStyle="bold"
android:id="@+id/txtView"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/rdGroup"
android:layout_below="@+id/txtView">
<RadioButton
android:id="@+id/rdbJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="100dp"
android:text="Java"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:id="@+id/rdbPython"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="100dp"
android:text="Python"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:id="@+id/rdbAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="100dp"
android:text="Android"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:id="@+id/rdbAngular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="100dp"
android:text="AngularJS"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
<Button
android:id="@+id/getBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_below="@+id/rdGroup"
android:text="Get Course" />
</RelativeLayout>
MainActivity.java
package com.example.admin.radioexam1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
android = (RadioButton)findViewById(R.id.rdbAndroid);
angular = (RadioButton)findViewById(R.id.rdbAngular);
java = (RadioButton)findViewById(R.id.rdbJava);
python = (RadioButton)findViewById(R.id.rdbPython);
Button btn = (Button)findViewById(R.id.getBtn);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String result = "Selected Course: ";
result+=
(android.isChecked())?"Android":(angular.isChecked())?"AngularJS":(java.isChecked())?"Java":
(python.isChecked())?"Python":"";
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
}
});
}
public void onRadioButtonClicked(View view)
{
boolean checked = ((RadioButton)
view).isChecked(); String str="";
switch(view.getId())
{
case R.id.rdbAndroid:
if(checked)
str = "Android Selected";
break;
case R.id.rdbAngular:
if(checked)
str = "AngularJS Selected";
break;
case R.id.rdbJava:
if(checked)
str = "Java Selected";
break;
case R.id.rdbPython:
if(checked)
str = "Python Selected";
break;
}
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();
}
}
OUTPUT:
Ex.No. 2. Add a Spinner. When the Spinner is selected, there should be three option (e.g.,
Android, Java, Testing).
Date :
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
activity_main.xml
<TextView
android:id="@+id/txtVw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="150dp"
android:text="Select User:"
android:textStyle="bold"
android:textSize="15dp" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/txtVw"
android:layout_toRightOf="@+id/txtVw" />
</RelativeLayout>
MainActivity.java
package com.tutlane.spinnerexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
Date:
AIM :
ALGORITHM :
1. In the layout create a textbox and buttons for numbers and operators.
2. For each buttons get their id using findviewbyid() and setonclicklistener.
3. Create onclick() method to get the value of each button.
4. using switch statement compare the ids of the button.
5. Once matched invoke compute function to perform various operations.
PROGRAM :
activity_main.xml
<EditText
android:id="@+id/edt1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:textSize="28dp" />
<Button
android:id="@+id/button1"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="80dp"
android:textSize="28dp"
android:text="1" />
<Button
android:id="@+id/button2"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="80dp"
android:textSize="28dp"
android:text="2" />
<Button
android:id="@+id/button3"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="190dp"
android:layout_marginTop="80dp"
android:textSize="28dp"
android:text="3" />
<Button
android:id="@+id/button4"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="160dp"
android:textSize="28dp"
android:text="4" />
<Button
android:id="@+id/button5"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="160dp"
android:textSize="28dp"
android:text="5" />
<Button
android:id="@+id/button6"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="190dp"
android:layout_marginTop="160dp"
android:textSize="28dp"
android:text="6" />
<Button
android:id="@+id/button7"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="240dp"
android:textSize="28dp"
android:text="7" />
<Button
android:id="@+id/button8"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="240dp"
android:textSize="28dp"
android:text="8" />
<Button
android:id="@+id/button9"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="190dp"
android:layout_marginTop="240dp"
android:textSize="28dp"
android:text="9" />
<Button
android:id="@+id/buttonadd"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="270dp"
android:layout_marginTop="80dp"
android:textSize="28dp"
android:text="+" />
<Button
android:id="@+id/buttonsub"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="270dp"
android:layout_marginTop="160dp"
android:textSize="28dp"
android:text="-" />
<Button
android:id="@+id/buttonmul"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="270dp"
android:layout_marginTop="240dp"
android:textSize="28dp"
android:text="*" />
<Button
android:id="@+id/button10"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="320dp"
android:textSize="28dp"
android:text="." />
<Button
android:id="@+id/button0"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="320dp"
android:textSize="28dp"
android:text="0" />
<Button
android:id="@+id/buttonC"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="190dp"
android:layout_marginTop="320dp"
android:textSize="28dp"
android:text="C" />
<Button
android:id="@+id/buttondiv"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="270dp"
android:layout_marginTop="320dp"
android:textSize="28dp"
android:text="/" />
<Button
android:id="@+id/buttoneql"
android:layout_width="315dp"
android:layout_height="75dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="400dp"
android:textSize="28dp"
android:text="=" />
</RelativeLayout>
MainActivity.java
package com.crunchify.tutorials.crunchifycalculator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
buttonSub.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{ mValueOne = Float.parseFloat(crunchifyEditText.getText() +
""); mSubtract = true;
crunchifyEditText.setText(null); }
});
buttonMul.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{ mValueOne = Float.parseFloat(crunchifyEditText.getText() + "");
crunchifyMultiplication = true;
crunchifyEditText.setText(null); }
});
buttonDivision.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{ mValueOne = Float.parseFloat(crunchifyEditText.getText() + "");
crunchifyDivision = true;
crunchifyEditText.setText(null); }
});
buttonEqual.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{ mValueTwo = Float.parseFloat(crunchifyEditText.getText() +
""); if (crunchifyAddition == true)
{ crunchifyEditText.setText(mValueOne + mValueTwo + "");
crunchifyAddition = false; }
if (mSubtract == true)
{ crunchifyEditText.setText(mValueOne - mValueTwo + "");
mSubtract = false; }
if (crunchifyMultiplication == true)
{ crunchifyEditText.setText(mValueOne * mValueTwo +
""); crunchifyMultiplication = false; }
if (crunchifyDivision == true)
{ crunchifyEditText.setText(mValueOne / mValueTwo +
""); crunchifyDivision = false; }
}
});
buttonC.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{ crunchifyEditText.setText(""); }
});
button10.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{ crunchifyEditText.setText(crunchifyEditText.getText() + "."); }
});
}
}
OUTPUT:
Ex.No.4. Add two EditText. When a number is entered in Edit Text 1, the square of that
number should be displayed in Edit Text 2 as a separate Activity.
Date :
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
activity_main.xml
<EditText
android:id="@+id/et1"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="40dp"
android:inputType="number" />
<EditText
android:id="@+id/et2"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="90dp"
android:inputType="number"/>
<Button
android:id="@+id/bb1"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="200dp"
android:text="Result" /> </RelativeLayout>
MainActivity.java
package com.example.admin.new1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Long press me"
android:layout_marginTop="200dp" android:layout_marginLeft="100dp"/>
</LinearLayout>
MainActivity.java
package com.tutlane.contextmenuexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
Activity_main.xml
<Button
android:text="@string/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:onClick="exit"
android:textStyle="normal|bold"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="131dp"/>
<TextView
android:text="@string/click_over_button_to_exit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="68dp"
android:id="@+id/textView2"
android:layout_above="@+id/button"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:textStyle="normal|bold"
android:gravity="center"/>
</RelativeLayout>
MainActivity.java
package com.example.alertdialogexample;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
publicclassMainActivityextendsAppCompatActivity{
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
Activity_main.xml
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sending SMS Example"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point "
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_below="@+id/textView1"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/abc"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Enter Phone Number"
android:phoneNumber="true"
android:textColorHint="@color/abc_primary_text_material_dark"
android:layout_below="@+id/imageButton"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:textColorHint="@color/abc_primary_text_material_dark"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton"
android:hint="Enter SMS"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Sms"
android:id="@+id/btnSendSMS"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"/>
</RelativeLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<stringname="app_name">tutorialspoint</string>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialspoint">
<uses-permissionandroid:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.example.tutorialspoint.MainActivity"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.example.tutorialspoint;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
publicclassMainActivityextendsActivity{
privatestaticfinalint MY_PERMISSIONS_REQUEST_SEND_SMS =0;
Button sendBtn;
EditText txtphoneNo, txtMessage;
String phoneNo, message;
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and click
finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="34dp"
android:layout_marginTop="36dp"
android:contentDescription="@string/hello_world"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/imageView1"
android:text="@string/tap" android:textAppearance="?
android:attr/textAppearanceLarge" />
</RelativeLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Camera</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="tap">Tap the image to open the camera!!</string>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.c package="com.example.camera"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.camera.Mainandroid:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.example.camera;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
Date :
AIM:
To develop an application using GUI components
ALGORITHM:
Database - Insertion
mydatabase.execSQL("CREATE TABLE IF NOT EXISTS exam(Username
VARCHAR,Password VARCHAR);");
mydatabase.execSQL("INSERT INTO exam VALUES('admin','admin');");
Database - Fetching
Cursor resultSet = mydatbase.rawQuery("Select * from exam",null);
resultSet.moveToFirst();
String username = resultSet.getString(0);
String password = resultSet.getString(1);
Database – Helper
public class DBHelper extends SQLiteOpenHelper
{
public DBHelper()
{ super(context,DATABASE_NAME,null,1); }
public void onCreate(SQLiteDatabase db) {}
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp"
android:text="Data Base" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials Point"
android:id="@+id/textView2"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:textSize="35dp"
android:textColor="#ff16ff01" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:src="@drawable/logo"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_below="@+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
</ScrollView>
</RelativeLayout>
MainActivity.java
package com.example.sairamkrishna.myapplication;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
package com.example.sairamkrishna.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
package com.example.sairamkrishna.myapplication;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
AIM:
ALGORITHM:
3. Choose the android version. Choose the lowest android version (Android 2.2) and select
next.
4. Enter the package name. Package name must be two word separated by comma and
click finish.
6. Go to res folder and select layout. Double click the main.xml file.
9. Go to project explorer and src folder. Now select mainactivity.java file and type the code.
10. Now go to the main.xml and right click. Select run as option and select run configuration.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:src="@drawable/abc"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forward"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pause"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/back"
android:id="@+id/button3"
android:layout_alignTop="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rewind"
android:id="@+id/button4"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3"
android:layout_toEndOf="@+id/button3" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_alignLeft="@+id/textview"
android:layout_alignStart="@+id/textview"
android:layout_alignRight="@+id/textview"
android:layout_alignEnd="@+id/textview"
android:layout_above="@+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView2"
android:layout_above="@+id/seekBar"
android:layout_toLeftOf="@+id/textView"
android:layout_toStartOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textAppearance="?
android:id="@+id/textView3"
android:layout_above="@+id/seekBar"
android:layout_alignRight="@+id/button4"
android:layout_alignEnd="@+id/button4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView4"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_centerHorizontal="true" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sairamkrishna.myapplication.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.example.sairamkrishna.myapplication;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.concurrent.TimeUnit;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button)findViewById(R.id.button3);
b4 = (Button)findViewById(R.id.button4);
iv = (ImageView)findViewById(R.id.imageView);
tx1 = (TextView)findViewById(R.id.textView2);
tx2 = (TextView)findViewById(R.id.textView3);
tx3 = (TextView)findViewById(R.id.textView4);
tx3.setText("Song.mp3");
seekbar = (SeekBar)findViewById(R.id.seekBar);
seekbar.setClickable(false);
b2.setEnabled(false);
b3.setOnClickListener(new View.OnClickListener() {
Toast.makeText(getApplicationContext(), "Playing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.start();
finalTime = mediaPlayer.getDuration();
startTime = mediaPlayer.getCurrentPosition();
if (oneTimeOnly == 0) {
seekbar.setMax((int) finalTime);
oneTimeOnly = 1;
}
tx2.setText(String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)
finalTime)))
);
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)
startTime)))
);
seekbar.setProgress((int)startTime);
myHandler.postDelayed(UpdateSongTime,100);
b2.setEnabled(true);
b3.setEnabled(false);
});
b2.setOnClickListener(new View.OnClickListener() {
Toast.makeText(getApplicationContext(), "Pausing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.pause();
b2.setEnabled(false);
b3.setEnabled(true);
});
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
if((temp+forwardTime)<=finalTime){
mediaPlayer.seekTo((int) startTime);
seconds",Toast.LENGTH_SHORT).show();
}else{
seconds",Toast.LENGTH_SHORT).show();
});
b4.setOnClickListener(new View.OnClickListener() {
if((temp-backwardTime)>0){
mediaPlayer.seekTo((int) startTime);
seconds",Toast.LENGTH_SHORT).show();
}else{
seconds",Toast.LENGTH_SHORT).show();
});
}
private Runnable UpdateSongTime = new Runnable() {
startTime = mediaPlayer.getCurrentPosition();
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime)))
);
seekbar.setProgress((int)startTime);
myHandler.postDelayed(this, 100);
};
}
OUTPUT:
Ex. No.11. Create a thread, which performs a single task, and perform multithreading in
Android.
Date:
AIM:
To implement an application that implements Multithreading.
ALGORITHM:
1. In the design layout add two textviews and a button.
2. In mainactivity java file,create object for handler class.
3. using handler object invoke postDelayedfuntion.
4. Create object for runnable class.
5. Inside run method call a userdefined function.This function has an explicit intent
to invoke a webpage.
6. Oncreate thread starts followed by runnable thread.
PROGRAM :
MainActivity.java
package com.example.multithread;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.TextView;