Procuring digital preservation CAN be quick and painless with our new dynamic...
Android Lab Mannual 18SUITSP5.docx
1. 1 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
TABLEOF CONTENTS
S. NO. DATE CONTENTS
PAGE
NO.
SIGNATURE
1. DEVELOPMENT OF HELLO WORLD APPLICATION 4
2. AN APPLICATION SHOWS HELLO MESSAGE
ALONG WITH THE NAME
11
3. DESIGN AN ANDROID APPLICATION SEND SMS
USING INTERNET
15
4. DESIGN AN ANDROID APPLICATION FOR MENU 18
5. PHONE CONTACTS IN VERTICALLINEAR MANNER 22
6. AN APPLICATION THAT DRAWS BASIC GRAPHICAL
PRIMITIVES
27
7. AN MOBILEAPPLICATION THAT CREATE,SAVE, UPDATE
AND DELETE DATA IN DATABASE
29
8. AN APPLICATION THAT IMPLEMENTS MULTI
THREADING
36
9. ARITHMATIC OPERATIONS 40
10. AN APPLICATION USING FRAGMENTS 45
11. HIDE THE TITLE BAR 49
12. SELECT GENDER USING RADIO BUTTON 51
2. 2 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
E X . N O : 1
D a t e :
DEVELOPMENT OF HELLO WORLD APPLICATION
AIM:
To designan android application to display Hello World
First stepis to create a simple Android Application using Android studio. When you click on
Android studio icon, it will show screen as shown below
You can start your application development by calling start a new android studio project. in a new
installationframe should ask Application name, package information and location of the project.−
3. 3 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
Configure the Hello World Project Details
We'llfinishcreating the project by configuring some details about its name, location, and the API
version it
Changethe name of the application. Change the default Project location toyour preferred
directory or just leave it as the default location.
On the minimum API level, ensure that API 15: Android 4.0.3 IceCreamSandwich is set as the
Minimum SDK. This ensures that your application runs on almost all devices.
4. 4 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
The next level of installation should contain selecting the activity to mobile, it specifies the default
layout for Applications.
5. 5 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SOURCE CODE :
TheMain Activity File
Themain activity codeisa Java fileMainActivity.java. Thisis theactual application file which
ultimately gets converted to a Dalvik executable and runs your application
packagecom.example.helloworldapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
TheLayout File
The activity_main.xml is a layout file available in res/layout directory, that is referenced by your
application when building its interface. You will modify this file very frequently to change the
layout of your application. For your "Hello World!" application,this file will have following content
related to default layout −
<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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
6. 6 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
I )Running app on Phone:
Connect your Phone toComputer
Plug in your device toyour computer with a USB cable. If you're developing on Windows, you might need
to install this universal ADB USB driver or find your specific USB driver for your device.
Enable USB Debugging
The next stepis to enable USB debugging soyour phone can interact with your computer in a developer mode.
The following steps are needed:
1. (Windows Only) Install this ADBDriver
2. Plug-inyour Android Device to Computer via USB
3. Open the "Settings" App on the Device
4. Scroll down to bottom to find "About phone" item
5. Scroll down to bottom to find "Build number" section
6. Tapon "Build Number" 7 times in quick succession
7. You should see the message "Youare now a developer!"
8. Go back to main "Settings" page
9. Scroll down bottom to find "Developer options" item
10. Turn on "USB Debugging" switch and hit "OK"
11. Unplug and re-plug the device
12. Dialog appears "Allow USB Debugging?"
13. Check"Always allow from this computer" and then hit "OK"
7. 7 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
Running your App
Now, we can launch apps from Android Studio onto our device:
1. Select one of your projects and click "Run" from the toolbar.
2. In the "Choose Device" window that appears,select the "Choose a running device" radio button, select the
device, and click OK.
II)Running app on Emulator(AVD)
To run the app from Android studio, open one of your project's activity files and click Run icon from the tool
bar. Android studio installs the app on your AVD and starts it and if everything is fine with your set-up and
application,it willdisplay following Emulator window −Once Gradle finishes building,Android Studio should install
the app on your connected device and start it.
8. 8 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
Sample Output:
Actual Output :
Result:
9. 9 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
E X . N O : 2
D A T E :
AIM:
AN APPLICATION SHOWS HELLO MESSAGE ALONG WITH THENAME
To Create an application that takes thename from a text box and shows hello message along with thename
entered in text box, when the user clicks the OK button.
Codefor MainActivity.java
packagecom.example.akshay.mrcet;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// These are the global variables EditText editName, editPassword;TextView result;
Button buttonSubmit, buttonReset;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editName = (EditText) findViewById(R.id.editName);
editPassword = (EditText) findViewById(R.id.editPassword);
result = (TextView) findViewById(R.id.tvResult);
buttonSubmit = (Button) findViewById(R.id.buttonSubmit);
buttonReset = (Button) findViewById(R.id.buttonReset);
/*
Submit Button
*/
buttonSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = editName.getText().toString();
String password = editPassword.getText().toString();
result.setText("Name:t" + name + "nPassword:t" + password );
10. 10 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
}
});
/*
Reset Button
*/
buttonReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {editName.setText("");
editPassword.setText("");
result.setText("");
editName.requestFocus();
}
});
}
}
activity_main.xml
<?xml version="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns: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"
android:background="#FFFF8D"
tools:context="com.example.akshay.mrcet.MainActivity">
<TextViewandroid:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true
"android:layout_alignParentTop="true"
android:text="NAME"
android:textSize="20sp"
android:layout_margin="20dp" />
<TextViewandroid:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="PASSWORD"
android:layout_marginTop="38dp"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView" />
<EditTextandroid:id="@+id/editName"
11. 11 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="EnterName"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/editPassword"
android:layout_alignStart="@+id/editPassword" />
<EditTextandroid:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="EnterPassword"
android:inputType="textPassword"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp" />
<Buttonandroid:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:text="SUBMIT" />
<Button android:id="@+id/buttonReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESET"
android:layout_alignBaseline="@+id/buttonSubmit"
android:layout_alignBottom="@+id/buttonSubmit"
android:layout_centerHorizontal="true" />
<TextViewandroid:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="143dp"
android:textSize="30sp"
12. 12 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
Sample Output:
Actual Output :
Result:
13. 13 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.NO :3
DATE :
DESIGN AN ANDROID APPLICATION SENDING SMS USING INTERNET
AIM :
To designan android application Send SMS using Intent.
MainActivity.java
package com.example.sms;
import android.os.Bundle;
import android.app.Activity;
import android.telephony.gsm.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt=(Button)findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage("5554", null,"hai", null, null);
}
});
14. 14 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
}
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
MainActivity.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" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="54dp"
android:layout_marginTop="166dp"
android:text="send" />
</RelativeLayout>
15. 15 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLEOUTPUT:
ACTUAL OUTPUT
RESULT:
16. 16 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.NO :4
DATE :
DESIGN AN ANDROID APPLICATION FOR MENU
AIM:
To designan application options menu.
MainActivity.java
package com.javatpoint.optionmenu;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);//Menu Resource, Menu
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
17. 17 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
caseR.id.item1:
Toast.makeText(getApplicationContext(),"Item 1 Selected",Toast.LENGTH_LONG).show();
return true;
caseR.id.item2:
Toast.makeText(getApplicationContext(),"Item 2 Selected",Toast.LENGTH_LONG).show();
return true;
caseR.id.item3:
Toast.makeText(getApplicationContext(),"Item 3 Selected",Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
MainActivity.xml
<RelativeLayout xmlns:androclass="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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
18. 18 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SecondActivity.xml
<menu xmlns:androclass="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/item1"
android:title="Item 1"/>
<item android:id="@+id/item2"
android:title="Item 2"/>
<item android:id="@+id/item3"
android:title="Item 3"/>
</menu>
19. 19 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLEOUTPUT:
ACTUAL OUTPUT:
Result:
20. 20 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.NO : 5
DATE :
AIM:
PHONECONTACTS IN VERTICAL LINEAR MANNER
To Designanapplicationthatcontains phone contacts invertical linearmanner.Selected contact
appears at the top of the list with a large italicized font and ablue background.
Procedure:
Creating aNew project:
▪ Open Android Studio and then click on File -> New -> New project.
▪ Then type the Application name as “ex.no.10″ and click Next.
21. 21 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
▪ Then select the Minimum SDKas shown below and click Next.
▪ Then selectthe Empty Activity and click Next.
22. 22 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
▪ Finallyclick Finish.
▪ It will take some time to build and load the project.
▪ After completion it will look as given below.
23. 23 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
XML code
<Button android:id="@+id/button_call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onclickphonecall"
android:text="XYZ"
tools:layout_editor_absoluteX="131dp"
tools:layout_editor_absoluteY="59dp" />
public void onclickphonecall(View v) {String
URL="1234567890";
Uri u= Uri.parse("tel:"+URL);
Intent i=new Intent(Intent.ACTION_VIEW, u);
startActivity(i);
24. 24 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLE OUTPUT:-
ACTUAL OUTPUT:-
Result:
25. 25 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.NO : 6
DATE :
AN APPLICATION THATDRAWS BASICGRAPHICAL PRIMITIVES
AIM:
To Devisean application that draws basicgraphicalprimitives(rectangle,circle)on thescreen.
XML Code
<ImageView
android:id="@+id/imageView_graphics"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="13dp" />
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graphical_operation);
Bitmap bg= Bitmap.createBitmap(720,1280,Bitmap.Config.ARGB_8888);
ImageView I= (ImageView)findViewById(R.id.imageView_graphics);
I.setBackgroundDrawable(new BitmapDrawable(bg));
Canvas canvas = newCanvas(bg);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(50);
canvas.drawText("Rectangle",420, 150,paint);
canvas.drawRect(400, 200, 650, 700, paint);
paint.setColor(Color.RED);
canvas.drawText("Circle",120, 150,paint);
canvas.drawCircle(200, 350, 150, paint);
paint.setColor(Color.GREEN);
canvas.drawText("Square",120, 800, paint);
canvas.drawRect(50,850, 350, 1150, paint);
paint.setColor(Color.BLACK);
canvas.drawText("Line",480, 800, paint);
canvas.drawLine(520, 850, 520, 1150, paint);
}
26. 26 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLE OUTPUT:-
ACTUALOUTPUT:-
RESULT:-
27. 27 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.NO : 7
DATE :
AN MOBILE APPLICATION THAT CREATE, SAVE,UPDATEAND DELETEDATA IN DATABASE
AIM:
To build an mobileapplication that create, save,updateand deletedata in database.
Main Activity.java
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText;
public class MainActivity extends AppCompatActivity implements
android.view.View.OnClickListener{
EditText Rollno,Name,Marks;
Button Insert,Delete,Update,View,ViewAll;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Rollno=(EditText)findViewById(R.id.Rollno);
Name=(EditText)findViewById(R.id.Name);
Marks=(EditText)findViewById(R.id.Marks);
Insert=(Button)findViewById(R.id.Insert);
Delete=(Button)findViewById(R.id.Delete);
Update=(Button)findViewById(R.id.Update);
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Insert.setOnClickListener(this);
Delete.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
ViewAll.setOnClickListener(this);
db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATETABLEIF NOT EXISTS student(rollVARCHAR,nameVARCHAR,"
+"marks VARCHAR);");
28. 28 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
}
public void onClick(Viewview)
{
if(view==Insert)
{
if(Rollno.getText().toString().trim().length()==0||
Name.getText().toString().trim().length()==0||
Marks.getText().toString().trim().length()==0)
{
showMessage("Error","Pleaseenter allvalues");return;
}
db.execSQL("INSERT INTO student
VALUES('"+Rollno.getText()+"','"+Name.getText()+"','"+Marks.getText()+"');");
showMessage("Success", "Record added");
clearText();
}
if(view==Delete)
{
if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error","Pleaseenter Rollno");return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
rollno='"+Rollno.getText()+"'",null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM student WHERE rollno='"+Rollno.getText()+"'");
showMessage("Success","Record Deleted");
}
else
{
showMessage("Error","Invalid Rollno");
}
clearText();
}
if(view==Update)
{
if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error","Pleaseenter Rollno");
29. 29 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
rollno='"+Rollno.getText()+"'",null);
if(c.moveToFirst()) {
db.execSQL("UPDATEstudent SET name='" +Name.getText()+ "',marks='" +
Marks.getText()+
"' WHERE rollno='"+Rollno.getText()+"'");
showMessage("Success","Record Modified");
}
else {
showMessage("Error","Invalid Rollno");
}
clearText();
}
if(view==View)
{
if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error","Pleaseenter Rollno");return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
rollno='"+Rollno.getText()+"'",null);
if(c.moveToFirst())
{
Name.setText(c.getString(1));
Marks.setText(c.getString(2));
}
else
{
showMessage("Error", "Invalid Rollno");
clearText();
}
}
if(view==ViewAll)
{
Cursor c=db.rawQuery("SELECT * FROM student", null);
if(c.getCount()==0)
{
showMessage("Error","No records found");return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToN
{
30. 30 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
buffer.append("Rollno: "+c.getString(0)+"n");
buffer.append("Name: "+c.getString(1)+"n");
buffer.append("Marks: "+c.getString(2)+"nn");
}
showMessage("Student Details", buffer.toString());
}
}
public void showMessage(String title,String message)
{
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
public void clearText()
{
Rollno.setText("");
Name.setText("");
Marks.setText("");
Rollno.requestFocus();
}
}
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp" android:layout_y="20dp"
android:text="Student Details"
android:textSize="30sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="110dp"
31. 31 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
android:text="Enter Rollno:"
android:textSize="20sp" />
<EditText android:id="@+id/Rollno"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="100dp"
android:inputType="number"
android:textSize="20sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="160dp" android:text="Enter
Name:" android:textSize="20sp" />
<EditText android:id="@+id/Name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="150dp"
android:inputType="text"
android:textSize="20sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="210dp" android:text="Enter
Marks:" android:textSize="20sp" />
<EditText android:id="@+id/Marks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="200dp"
android:inputType="number"
android:textSize="20sp" />
<Button android:id="@+id/Insert"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="300dp"
android:text="Insert"
android:textSize="30dp" />
32. 32 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
<Button
android:id="@+id/Delete"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="300dp" android:text="Delete"
android:textSize="30dp" />
<Button android:id="@+id/Update"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="400dp" android:text="Update"
android:textSize="30dp" />
<Button android:id="@+id/View"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="400dp" android:text="View"
android:textSize="30dp" />
<Button android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="100dp"
android:layout_y="500dp" android:text="View
All" android:textSize="30dp" />
</AbsoluteLayout>
33. 33 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLE OUTPUT:-
ACTUALOUTPUT:
RESULT:
34. 34 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.NO : 8
DATE :
AIM:
AN APPLICATION THATIMPLEMENTS MULTITHREADING
To Devise an application thatimplements Multithreading.
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extendsAppCompatActivity
{
ImageView img;
Button bt1,bt2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1= (Button)findViewById(R.id.button);
bt2=(Button) findViewById(R.id.button2);
img = (ImageView)findViewById(R.id.imageView);
bt1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
newThread(new Runnable()
{
@Override
public void run()
{
img.post(newRunnable()
{
@Override
public void run()
35. 35 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
{
Img.setImageResorce(R.drawable.india);
}
});
}
});
}).start();
}
Bt2.setOnClickListner(newView.OnClickListner()
{
@Override
PublicvoidonClick(View v)
{
new Thread(newRunnable()
{
@Override
Publicvoidrun()
{
@Override
Img.post(newRunnable()
{
{
}
});
}
@Override
Publicvoidrun()
Img.setImageResource(R.drawable.karanataka1);
}
});
}
}
}).start();
36. 36 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
.XMLfile
<?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" >
<ImageView android:id="@+id/imageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_margin="50dp"
android:layout_gravity="center" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center"
android:text="Load Image 1" />
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center"
android:text="Load image 2" />
</LinearLayout>
Note: : Before Running the Application, Copy the 2 Images(India & Karnataka) and Paste it in
“app -> res -> drawable” by pressing “right click mouse button on drawable”and selecting the
“Paste” option.
37. 37 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLE OUTPUT:-
ACTUALOUTPUT:
RESULT:
38. 38 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.No :9
Date :
AIM:
ARITHMETIC OPERATIONS
To Develop a standard calculator application toperformbasiccalculationslike
addition,subtraction,multiplication and division.
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.siri.calc.MainActivity">
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="153dp"
tools:layout_editor_absoluteY="9dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
tools:layout_editor_absoluteY="58dp"
tools:layout_editor_absoluteX="16dp"
android:layout_above="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="31dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
tools:layout_editor_absoluteY="125dp"
tools:layout_editor_absoluteX="16dp"
android:layout_above="@+id/button"
39. 39 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="43dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD" android:onClick="add"
tools:layout_editor_absoluteX="34dp"
tools:layout_editor_absoluteY="192dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/sub"
android:layout_toStartOf="@+id/sub"
android:layout_marginRight="52dp"
android:layout_marginEnd="52dp" />
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_toEndOf="@+id/editText2"
android:layout_toRightOf="@+id/editText2"
android:text="Sub"
android:onClick="sub"/>
<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/div"
android:layout_alignBottom="@+id/div"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button"
android:text="Mul"
android:onClick="mul" />
40. 40 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/sub"
android:layout_alignRight="@+id/sub"
android:layout_below="@+id/sub"
android:layout_marginTop="23dp"
android:text="Div" android:onClick="div" />
</RelativeLayout>
MainActivity.java
packagecom.example.siri.calc;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivityextends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void add(View v)
{
int num1, num2,sum;
EditText t1 = (EditText)findViewById(R.id.editText); EditText
t2 = (EditText)findViewById(R.id.editText2);TextView t3 =
(TextView)findViewById(R.id.result);num1 =
Integer.parseInt(t1.getText().toString()); num2 =
Integer.parseInt(t2.getText().toString()); sum = num1 + num2;
t3.setText(Integer.toString(sum));
}
public void sub(View v)
{
int num1, num2,sum;
EditText t1 = (EditText)findViewById(R.id.editText); EditText
t2 = (EditText)findViewById(R.id.editText2);TextView t3 =
(TextView)findViewById(R.id.result); num1 =
41. 41 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
Integer.parseInt(t1.getText().toString()); num2 =
Integer.parseInt(t2.getText().toString()); sum = num1 - num2;
t3.setText(Integer.toString(sum));
}
public void mul(View v)
{
int num1, num2,sum;
EditText t1 = (EditText)findViewById(R.id.editText);EditText
t2 = (EditText)findViewById(R.id.editText2);TextView t3 =
(TextView)findViewById(R.id.result);num1 =
Integer.parseInt(t1.getText().toString()); num2 =
Integer.parseInt(t2.getText().toString()); sum = num1 * num2;
t3.setText(Integer.toString(sum));
}
public void div(View v)
{
int num1, num2,sum;
EditText t1 = (EditText)findViewById(R.id.editText);EditText
t2 = (EditText)findViewById(R.id.editText2);TextView t3 =
(TextView)findViewById(R.id.result);num1 =
Integer.parseInt(t1.getText().toString()); num2 =
Integer.parseInt(t2.getText().toString()); sum = num1 / num2;
t3.setText(Integer.toString(sum));
}
}
42. 42 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLE OUTPUT:-
ACTUALOUTPUT:
Result:
43. 43 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.No :10
Date :
AIM:
AN APPLICATION USING FRAGMENTS
To Create an android application using Fragments
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="fill_parent"
android:layout_height="fill_parent"
tools:context="example.javatpoint.com.fragmentexample.MainActivity">
<fragment
android:id="@+id/fragment1"
android:name="example.javatpoint.com.fragmentexample.Fragment1"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<fragment
android:id="@+id/fragment2"
android:name="example.javatpoint.com.fragmentexample.Fragment2"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
fragment_fragment1.xml
<FrameLayout 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:background="#F5F5DC"
tools:context="example.javatpoint.com.fragmentexample.Fragment1">
<!-- TODO:Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
44. 44 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
</FrameLayout>
File: fragment_fragment2.xml
<FrameLayout 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:background="#F0FFFF"
tools:context="example.javatpoint.com.fragmentexample.Fragment2">
<!-- TODO:Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
MainActivity class
File:
MainActivity.java
packageexample.javatpoint.com.fragmentexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
File: Fragment1.java
package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment1 extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
45. 45 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment1, container, false);
}
}
File: Fragment2.java
package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment2extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment2, container, false);
}
}
46. 46 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLE OUTPUT:
ACTUAL OUTPUT:
RESULT:
47. 47 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.No :11
Date :
AIM:
HIDE THE TITLE BAR
To Write a Android ProgramToExecute Hide The Title Bar
MainActivity.java
package first.javatpoint.com.hidetitlebar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
setContentView(R.layout.activity_main);
} }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="first.javatpoint.com.hidetitlebar.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
48. 48 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLEOUTPUT:
ACTUALOUTPUT:
RESULT:
49. 49 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
EX.No :12
Date :
AIM:
SELECT GENDERUSING RADIO BUTTON
To Write a Android Program To SelectGenderUsingRadioButton
MainActivity.java
package example.javatpoint.com.radiobutton;
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.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button;
RadioButton genderradioButton;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup=(RadioGroup)findViewById(R.id.radioGroup);
}
public void onclickbuttonMethod(View v){
int selectedId = radioGroup.getCheckedRadioButtonId();
genderradioButton = (RadioButton) findViewById(selectedId);
if(selectedId==-1){
Toast.makeText(MainActivity.this,"Nothing selected", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this,genderradioButton.getText(), Toast.LENGTH_SHORT).show();
}
}
}
50. 50 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
tools:context="example.javatpoint.com.radiobutton.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:textSize="22dp"
android:text="Single Radio Buttons" />
<!-- Default RadioButtons -->
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Radio Button 1"
android:layout_marginTop="20dp"
android:textSize="20dp" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Radio Button 2"
android:layout_marginTop="10dp"
android:textSize="20dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="20dp"
android:background="#B8B894" />
51. 51 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:textSize="22dp"
android:text="Radio button inside RadioGroup" />
<!-- Customized RadioButtons -->
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup">
<RadioButton
android:id="@+id/radioMale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Male"
android:layout_marginTop="10dp"
android:checked="false"
android:textSize="20dp" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Female"
android:layout_marginTop="20dp"
android:checked="false"
android:textSize="20dp" />
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:id="@+id/button"
android:onClick="onclickbuttonMethod"
android:layout_gravity="center_horizontal" />
</LinearLayout>
52. 52 | P a g e I I I B . S c ( I T ) / 1 8 U I T S P 5
SAMPLEOUTPUT:
ACTUAL OUTPUT:
RESULT: