SlideShare a Scribd company logo
1
1. (a) Create an Android application that shows Hello + name of the
user and run it on an emulator.
Create Android Application:
2
3
4
5
1.b) Create an application that takes the name from a text box and shows hello
message along with the name entered in text box, when the user clicks the OK
button.
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity {
private Button b;
EditText etname,etemail,etpassword;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.click);
tv=(TextView)findViewById(R.id.display);
tv.setMovementMethod(new ScrollingMovementMethod())
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
etname=(EditText)findViewById(R.id.name);
etemail=(EditText)findViewById(R.id.email);
etpassword=(EditText)findViewById(R.id.password);
tv.setText("Your Input:
n"+etname.getText().toString()+"n"+etemail.getText().toString()+"n"+etpassword.getText().to
String()+"nEnd.");
}
});
}
6
2. Create a screen that has input boxes for User Name, Password, Address,
Gender (radio buttons for male and female), Age (numeric), Date of Birth
(Date Picket), State (Spinner) and a Submit button. On clicking the submit
button, print all the data below the Submit Button. Use
Declare UI Elements in XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/fstTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Name" />
<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"/>
<Button
android:id="@+id/getName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Name" />
</LinearLayout>
Load XML Layout File from an Activity
protectedvoid onCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
7
Create UI Element at Runtime
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView1 = new TextView(this);
textView1.setText("Name:");
EditText editText1 = new EditText(this);
editText1.setText("Enter Name");
Button button1 = new Button(this);
button1.setText("Add Name");
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.addView(textView1);
linearLayout.addView(editText1);
linearLayout.addView(button1);
setContentView(linearLayout);
}
8
3. Develop an application that shows names as a list and on selecting a name
it should show the details of the candidate on the next screenwith a “Back”
button. If the screen is rotated to landscape mode (width greater than
height), then the screenshould show liston leftfragment and details onright
fragment instead of second screen with back button. Use Fragment
transactions and Rotation event listener.
public class AndroidListViewActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCre0ate(savedInstanceState);
// storing string resources into Array
String[] numbers = {"one","two","three","four"}
// here you store the array of string you got from the database
// Binding Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, numbers));
// refer the ArrayAdapter Document in developer.android.com
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// selected item
String num = ((TextView) view).getText().toString();
9
// Launching new Activity on selecting single List Item
Intent i = new Intent(getApplicationContext(), SingleListItem.class);
// sending data to new activity
i.putExtra("number", num);
startActivity(i);
}
});
}
}
The secondActivity to display the Particular item you have clicked should be
public class SingleListItem extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.single_list_item_view);
TextView txtProduct = (TextView) findViewById(R.id.product_label);
Intent i = getIntent();
// getting attached intent data
String product = i.getStringExtra("number");
// displaying selected product name
txtProduct.setText(product);
}
}
10
4. Develop an application that uses a menu with 3 options for dialing a
number, opening a website and to sendan SMS.On selecting an option, the
appropriate action should be invoked using intents.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:icon="@drawable/ic_new_game"
android:title="@string/new_game"
android:showAsAction="ifRoom"/>
<item android:id="@+id/help"
android:icon="@drawable/ic_help"
android:title="@string/help" />
</menu>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/file"
android:title="@string/file" >
<!-- "file" submenu -->
<menu>
<item android:id="@+id/create_new"
android:title="@string/create_new" />
<item android:id="@+id/open"
android:title="@string/open" />
</menu>
</item>
</menu>
11
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.new_game:
newGame();
return true;
case R.id.help:
showHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
12
5. Developan application that inserts some notifications into Notification area
and whenever a notification is inserted, it should show a toast with details
of the notification.
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: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="com.journaldev.notifications.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CREATE NOTIFICATION"
android:id="@+id/button"
13
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCEL NOTIFICATION"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_alignRight="@+id/button"
android:layout_alignEnd="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
MainAcivity.Java
package com.journaldev.notifications;
import android.app.NotificationManager;
import android.app.PendingIntent;
14
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;
import android.widget.Toast;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
}
@OnClick(R.id.button)
public void sendNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(android.R.drawable.ic_dialog_alert);
15
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.journaldev.com/"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
builder.setContentIntent(pendingIntent);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
builder.setContentTitle("Notifications Title");
builder.setContentText("Your notification content here.");
builder.setSubText("Tap to view the website.");
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
// Will display the notification in the notification bar
notificationManager.notify(1, builder.build());
}
@OnClick(R.id.button2)
public void cancelNotification() {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager)
getApplicationContext().getSystemService(ns);
nMgr.cancel(1);
}
}
16
6.Create an application that uses a text file to store user names and passwords (tab
separated fields and one record per line)
importjava.io.File;
importjava.io.FileOutputStream;
importjava.io.FileReader;
importjava.io.FileWriter;
publicclassMainActivityextendsAppCompatActivity{
EditTextCodNum;
EditTextPltNum;
RadioButtonradButA;
RadioButtonradButD;
RadioButtonradButS;
RadioButtonradButR;
RadioButtonradButO;
RadioButtonradButI;
@Override
protectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbartoolbar= (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
17
CodNum= (EditText) findViewById(R.id.CodNum);
PltNum= (EditText) findViewById(R.id.PltNum);
radButA = (RadioButton) findViewById(R.id.radButA);
radButD = (RadioButton) findViewById(R.id.radButD);
radButS = (RadioButton) findViewById(R.id.radButS);
radButR = (RadioButton) findViewById(R.id.radButR);
radButO = (RadioButton) findViewById(R.id.radButO);
radButI = (RadioButton) findViewById(R.id.radButI);
checkBoxMw= (CheckBox) findViewById(R.id.checkBoxMw);
checkBoxG7= (CheckBox) findViewById(R.id.checkBoxG7);
checkBoxGw= (CheckBox) findViewById(R.id.checkBoxGw);
checkBoxF= (CheckBox) findViewById(R.id.checkBoxF);
final FileOutputStreamoutputStream;
StringfileName ="feederTxtFile";
Button buttonS= (Button) findViewById(R.id.buttonS);
buttonS.setOnClickListener(newView.OnClickListener() {
@Override
publicvoidonClick(Viewv) {
try{
outputStream= openFileOutput(fileName,CONTEXT.MOOD_PRIVATE);
outputStream.write(String.getBytes());
outputStream.close();
18
}catch (Exceptione){
e.printStackTrace();
}
}
});
Button buttonE= (Button) findViewById(R.id.buttonE);
buttonE.setOnClickListener(new View.OnClickListener(){
@Override
publicvoidonClick(Viewv) {
//Editingtotextfile.
}
});
19
7.Create a user registration application that stores the user details in a database
table.
activity_login.xml.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
tools:context=".activities.LoginActivity">
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
20
android:orientation="vertical">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:src="@drawable/logo" />
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/textInputEditTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_email"
android:inputType="text"
21
android:maxLines="1"
android:textColor="@android:color/white" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/textInputEditTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_password"
android:inputType="textPassword"
android:maxLines="1"
android:textColor="@android:color/white" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
22
android:id="@+id/appCompatButtonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="@color/colorTextHint"
android:text="@string/text_login" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/textViewLinkRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="@string/text_not_member"
android:textSize="16dp" />
</android.support.v7.widget.LinearLayoutCompat>
</android.support.v4.widget.NestedScrollView>
23
8.Create a database and a user table where the details of login names and
passwords are stored. Insert some names and passwords initially. Now the
login details entered by the user should be verified with the database and
an appropriate dialog should be shown to the user.
package com.example.sairamkrishna.myapplication;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.support.v7.app.ActionBarActivity;
importandroid.os.Bundle;
importandroid.view.KeyEvent;
importandroid.view.Menu;
importandroid.view.MenuItem;
importandroid.view.View;
importandroid.widget.AdapterView;
importandroid.widget.ArrayAdapter;
importandroid.widget.AdapterView.OnItemClickListener;
importandroid.widget.ListView;
importjava.util.ArrayList;
importjava.util.List;
24
publicclassMainActivityextendsActionBarActivity{
publicfinal staticStringEXTRA_MESSAGE= "MESSAGE";
private ListViewobj;
DBHelpermydb;
@Override
protectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mydb= newDBHelper(this);
ArrayListarray_list= mydb.getAllCotacts();
ArrayAdapterarrayAdapter=newArrayAdapter(this,android.R.layout.simple_list_item_1,array_list);
obj = (ListView)findViewById(R.id.listView1);
obj.setAdapter(arrayAdapter);
obj.setOnItemClickListener(newOnItemClickListener(){
@Override
publicvoidonItemClick(AdapterView<?>arg0,View arg1,int arg2,longarg3) {
//TODO Auto-generatedmethodstub
intid_To_Search= arg2 + 1;
Bundle dataBundle =newBundle();
dataBundle.putInt("id",id_To_Search);
25
Intentintent=newIntent(getApplicationContext(),DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);
}
});
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu) {
// Inflate the menu;thisaddsitemstothe actionbar if it ispresent.
getMenuInflater().inflate(R.menu.menu_main,menu);
returntrue;
}
@Override
publicbooleanonOptionsItemSelected(MenuItemitem){
super.onOptionsItemSelected(item);
switch(item.getItemId()) {
case R.id.item1:Bundle dataBundle=new Bundle();
dataBundle.putInt("id",0);
Intentintent=new Intent(getApplicationContext(),DisplayContact.class);
intent.putExtras(dataBundle);
26
startActivity(intent);
returntrue;
default:
returnsuper.onOptionsItemSelected(item);
}
}
publicbooleanonKeyDown(intkeycode,KeyEventevent) {
if (keycode ==KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
}
returnsuper.onKeyDown(keycode,event);
}
}

More Related Content

Similar to Android App Dev Manual-1.doc (20)

DOCX
Layout
deepikasony
 
PDF
Android tutorial
Abid Khan
 
PPTX
Android Development for Beginners with Sample Project - Day 1
Joemarie Amparo
 
PPTX
Android Development Training for Beginners - Activity
Joemarie Amparo
 
PPT
Android classes in mumbai
Vibrant Technologies & Computers
 
PPT
Android
San Bunna
 
PPTX
Introduction to android
Shrijan Tiwari
 
DOCX
Android Lab Mannual 18SUITSP5.docx
karthikaparthasarath
 
DOCX
Leture5 exercise onactivities
maamir farooq
 
DOCX
Lecture exercise on activities
maamir farooq
 
PPTX
04 activities - Android
Wingston
 
KEY
Android Workshop
Junda Ong
 
ODP
Android tutorials8 todo_list
Vlad Kolesnyk
 
PPTX
Engibrainz android syllabus
Varun B P
 
PPT
Synapseindia android apps introduction hello world
Tarunsingh198
 
PDF
Rohit android lab projects in suresh gyan vihar
Rohit malav
 
PDF
Android Basic Components
Jussi Pohjolainen
 
PDF
Android session 3
Ahesanali Suthar
 
PDF
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
ODP
Android tutorials8 todo_list
Vlad Kolesnyk
 
Layout
deepikasony
 
Android tutorial
Abid Khan
 
Android Development for Beginners with Sample Project - Day 1
Joemarie Amparo
 
Android Development Training for Beginners - Activity
Joemarie Amparo
 
Android classes in mumbai
Vibrant Technologies & Computers
 
Android
San Bunna
 
Introduction to android
Shrijan Tiwari
 
Android Lab Mannual 18SUITSP5.docx
karthikaparthasarath
 
Leture5 exercise onactivities
maamir farooq
 
Lecture exercise on activities
maamir farooq
 
04 activities - Android
Wingston
 
Android Workshop
Junda Ong
 
Android tutorials8 todo_list
Vlad Kolesnyk
 
Engibrainz android syllabus
Varun B P
 
Synapseindia android apps introduction hello world
Tarunsingh198
 
Rohit android lab projects in suresh gyan vihar
Rohit malav
 
Android Basic Components
Jussi Pohjolainen
 
Android session 3
Ahesanali Suthar
 
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Android tutorials8 todo_list
Vlad Kolesnyk
 

Recently uploaded (20)

PPTX
Grade 8Asian-Performing-Arts-A-Journey.pptx
MarieClaireSarmiento
 
PPTX
Prezentare_Cuprins232323131_Actualizat.pptx
Catalin284758
 
PPTX
hanna Kimberly retail scavenger hunt for FeeLit Records
KimberlyHanna5
 
PPTX
一比一原版(FIRENZE毕业证)佛罗伦萨美术学院毕业证如何办理
Taqyea
 
PPTX
Pretty Aesthetic Notes for .pptxpptxpptxpptx
RoshelleBonDacara
 
PPTX
City文凭办理|办理伦敦城市大学毕业证假文凭100%复刻
Taqyea
 
PDF
Rooted and Rising: The Story of Joseph Kim Nolensville Tennessee and Joseph K...
Joseph Kim Nolensville Tennessee
 
PPTX
Presentation social. Sjjsiejensjhshdsjsn
jamjamkyong
 
PPTX
法国电子毕业证巴黎第二大学成绩单激光标Paris 2学费发票办理学历认证
Taqyea
 
PPTX
The Victoriannnnnnnnnnnnnnnnnnnn Age.pptx
AlbertoTierra
 
PPTX
Tarpaulin for School Intramurals including the different Level and has a diff...
YuleEspinosaAbay
 
PPTX
学位成绩单修改CUE毕业证(埃德蒙顿康考迪亚大学毕业证书)海牙认证在线购买
Taqyea
 
PDF
Joseph Kim: Bridging Peace and Purpose Between Nolensville and Nashville
Joseph Kim Nolensville Tennessee
 
PPTX
tarte brand discovery and identity guidelines assignment.pptx
flamestar018
 
DOCX
U1- A7mkl,koikmkmkkmkmn, jkuhyjkml,kmjh.docx
ngoquynhanh17122006
 
PPTX
Biomolecules ppt .......................
priyranjankoncho123
 
PPTX
Title Lorem Ipsummmmmmmmmmmmmmmmmmm.pptx
221520010
 
PPTX
preporting 21st century aira and joseph clasio.pptx
jamescarllfelomino6
 
PDF
Joseph Kim Tennessee: Grounded in Nolensville, Rising in Nashville
Joseph Kim Nolensville Tennessee
 
PDF
3581759.pdfdfdsfdsfdsfdsfdsffdsfdsfdsfdsfdsfds
SachinThanekar6
 
Grade 8Asian-Performing-Arts-A-Journey.pptx
MarieClaireSarmiento
 
Prezentare_Cuprins232323131_Actualizat.pptx
Catalin284758
 
hanna Kimberly retail scavenger hunt for FeeLit Records
KimberlyHanna5
 
一比一原版(FIRENZE毕业证)佛罗伦萨美术学院毕业证如何办理
Taqyea
 
Pretty Aesthetic Notes for .pptxpptxpptxpptx
RoshelleBonDacara
 
City文凭办理|办理伦敦城市大学毕业证假文凭100%复刻
Taqyea
 
Rooted and Rising: The Story of Joseph Kim Nolensville Tennessee and Joseph K...
Joseph Kim Nolensville Tennessee
 
Presentation social. Sjjsiejensjhshdsjsn
jamjamkyong
 
法国电子毕业证巴黎第二大学成绩单激光标Paris 2学费发票办理学历认证
Taqyea
 
The Victoriannnnnnnnnnnnnnnnnnnn Age.pptx
AlbertoTierra
 
Tarpaulin for School Intramurals including the different Level and has a diff...
YuleEspinosaAbay
 
学位成绩单修改CUE毕业证(埃德蒙顿康考迪亚大学毕业证书)海牙认证在线购买
Taqyea
 
Joseph Kim: Bridging Peace and Purpose Between Nolensville and Nashville
Joseph Kim Nolensville Tennessee
 
tarte brand discovery and identity guidelines assignment.pptx
flamestar018
 
U1- A7mkl,koikmkmkkmkmn, jkuhyjkml,kmjh.docx
ngoquynhanh17122006
 
Biomolecules ppt .......................
priyranjankoncho123
 
Title Lorem Ipsummmmmmmmmmmmmmmmmmm.pptx
221520010
 
preporting 21st century aira and joseph clasio.pptx
jamescarllfelomino6
 
Joseph Kim Tennessee: Grounded in Nolensville, Rising in Nashville
Joseph Kim Nolensville Tennessee
 
3581759.pdfdfdsfdsfdsfdsfdsffdsfdsfdsfdsfdsfds
SachinThanekar6
 
Ad

Android App Dev Manual-1.doc