Android App Development Basics
Android App Development Basics
Program:
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="76dp"
android:layout_marginTop="42dp"
android:text="@string/tv" />
<EditText
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:ems="10"
android:hint="@string/txt"
android:text="@string/txt" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/btn" />
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:size="35dp"
android:text="@string/tv2" />
</RelativeLayout>
[Link]
[Link]. mypro1;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclassMainActivityextends Activity
{
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
Button b=(Button)findViewById([Link]);
[Link]([Link]()
{
@Override
publicvoidonClick(View v)
{
EditText et=(EditText)findViewById([Link]);
TextView tv=(TextView)findViewById([Link].tv2);
[Link]([Link]());
}
});
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Program:
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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="104dp"
android:layout_marginTop="142dp"
android:onClick="next"
android:text="@string/next" />
</RelativeLayout>
activity_main1.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="142dp"
android:text="@string/tv" />
</RelativeLayout>
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link]
package [Link].mypro2;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclassMainActivityextends Activity
{
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
publicvoidnext(View v)
{
Intent i=newIntent();
[Link](newComponentName(this, [Link]));
startActivity(i);
}
}
[Link]
package [Link].mypro2;
[Link];
[Link];
[Link];
publicclass Welcome extends Activity
{
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main1);
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
returntrue;
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Program:
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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">
<fragment
android:id="@+id/fragment2"
android:name="[Link]. mypro3.Fragment2"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/fragment1"
android:layout_marginTop="22dp" />
<fragment
android:id="@+id/fragment1"
android:name="[Link]. mypro3.Fragment1"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="22dp" />
</RelativeLayout>
[Link]
<FrameLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b22222">
<TextView
android:id="@+id/textView1"
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:layout_marginTop="34dp"
android:gravity="center"
android:text="@string/tv"
android:textSize="40sp"
android:textStyle="bold" />
</FrameLayout>
[Link]
<FrameLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#228b22">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:layout_marginTop="34dp"
android:gravity="center"
android:textStyle="bold"
android:textSize="40sp"
android:text="@string/TV"/>
</FrameLayout>
[Link]
package [Link].mypro3;
[Link];
[Link];
[Link];
import [Link];
@SuppressWarnings("unused")
publicclassMainActivityextends Activity {
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
getMenuInflater().inflate([Link], menu);
returntrue;
}
}
[Link]
[Link].mypro3;
[Link];
[Link];
[Link];
[Link];
[Link];
publicclass Fragment1 extends Fragment
{
@Override
public View onCreateView(LayoutInflaterinflater,ViewGroupcontainer,Bundle
savedInstanceState)
{
[Link]([Link].fragment1,container,false);
}
}
[Link]
package [Link].mypro3;
[Link];
[Link];
[Link];
[Link];
[Link];
publicclass Fragment2 extends Fragment
{
@Override
public View onCreateView(LayoutInflaterinflater,ViewGroupcontainer,Bundle
savedInstanceState)
{
[Link]([Link].fragment2,container,false);
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Program:
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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">
<EditText
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="39dp"
android:ems="10"
android:hint="@string/txt"
android:text="@string/txt">
<requestFocus />
</EditText>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txt"
android:layout_below="@+id/txt"
android:layout_marginLeft="15dp"
android:layout_marginTop="32dp"
android:text="@string/tv" />
<RadioGroup
android:id="@+id/MyradioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txt"
android:layout_centerVertical="true">
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
<RadioButton
android:id="@+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/rb" />
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rb1" />
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rb2" />
</RadioGroup>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/MyradioGroup"
android:layout_below="@+id/MyradioGroup"
android:layout_marginTop="29dp"
android:text="@string/btn" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/btn"
android:layout_marginBottom="30dp"
android:text="@string/tv2" />
</RelativeLayout>
[Link]
package [Link].mypro4;
[Link];
[Link];
[Link];
[Link];
[Link];
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclassMainActivityextends Activity
{
privateRadioGroupradioGroup;
@SuppressWarnings("unused")
privateRadioButtonmale,female,tgen;
privateEditText name;
private Button btn;
privateTextView tv;
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
radioGroup=(RadioGroup) findViewById([Link]);
[Link](new
OnCheckedChangeListener()
{
@Override
publicvoidonCheckedChanged(RadioGroup group , int checked) {
// TODO Auto-generated method stub
if(checked==[Link])
{
[Link](getApplicationContext(),
"choice: Male",Toast.LENGTH_SHORT).show();
}
elseif(checked == [Link].rb1)
{
[Link](getApplicationContext(), "choice:
Female",Toast.LENGTH_SHORT).show();
}
else
{
[Link](getApplicationContext(), "choice:
others",Toast.LENGTH_SHORT).show();
}
}
});
name=(EditText) findViewById([Link]);
male=(RadioButton)findViewById([Link]);
female=(RadioButton)findViewById([Link].rb1);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
tgen=(RadioButton)findViewById([Link].rb2);
tv=(TextView)findViewById([Link].tv2);
btn=(Button)findViewById([Link]);
[Link](newOnClickListener()
{
@Override
publicvoidonClick(View v)
{
// TODO Auto-generated method stub
intselectedId = [Link]();
if(selectedId == [Link]())
{
[Link]("Given Details are \n
name:"+[Link]()+" Gender: Male");
}
elseif(selectedId == [Link]())
{
[Link]("Given Details are \n
name:"+[Link]()+" Gender: Female");
}
else
{
[Link]("Given Details are \n
name:"+[Link]()+" Gender: Others");
}
}
});
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
returntrue;
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Program:
activity_main.xml
<LinearLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SELECT FRUITS:" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="66dp"
android:layout_marginTop="15dp"
android:text="@string/cb1" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="66dp"
android:layout_marginTop="15dp"
android:text="@string/cb2" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="66dp"
android:layout_marginTop="15dp"
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
android:text="@string/cb3" />
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="66dp"
android:layout_marginTop="15dp"
android:text="@string/tbtn"
android:textOff="ORDER"
android:textOn="ORDERED" />
<LinearLayout
android:layout_width="216dp"
android:layout_height="36dp"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:src="@drawable/img3" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:src="@drawable/img1" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:src="@drawable/images" />
</LinearLayout>
</LinearLayout>
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link]
package [Link].myproo55;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclassMainActivityextends Activity {
CheckBox ch1,ch2,ch3;
Button buttonOrder;
ImageButton imgbtn1,imgbtn2,imgbtn3;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
addListenerOnButtonClick();
}
privatevoidaddListenerOnButtonClick() {
// TODO Auto-generated method stub
ch1=(CheckBox)findViewById([Link].checkBox1);
ch2=(CheckBox)findViewById([Link].checkBox2);
ch3=(CheckBox)findViewById([Link].checkBox3);
buttonOrder=(Button)findViewById([Link].toggleButton1);
imgbtn1=(ImageButton)findViewById([Link].imageButton1);
imgbtn2=(ImageButton)findViewById([Link].imageButton2);
imgbtn3=(ImageButton)findViewById([Link].imageButton3);
[Link](newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
inttotalamount=0;
StringBuilder result=newStringBuilder();
[Link]("Selected Items:");
if([Link]())
{
[Link]("\nApple 100Rs");
totalamount+=100;
}
if([Link]())
{
[Link]("\nMango 50Rs");
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
totalamount+=50;
}
if([Link]()){
[Link]("\nOrange 120Rs");
totalamount+=120;
}
[Link]("\nTotal: "+totalamount+"Rs");
//Displaying the message on the toast
[Link](getApplicationContext(), [Link](),
Toast.LENGTH_LONG).show();
}
});
[Link](newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
[Link](getApplicationContext(), "Selected Apple",
Toast.LENGTH_LONG).show();
}
});
[Link](newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
[Link](getApplicationContext(), "Selected
Mango", Toast.LENGTH_LONG).show();
}
});
[Link](newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
[Link](getApplicationContext(), "Selected
Orango", Toast.LENGTH_LONG).show();
}
});
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Program:
activity_main.xml
<LinearLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Rollno"
android:text="@string/et1">
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter name"
android:text="@string/et2" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter course"
android:text="@string/et3" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="insert"
android:text="@string/btn1" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:onClick="read"
android:text="@string/btn2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="update"
android:text="@string/btn3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="delete"
android:text="@string/btn4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="@+id/listView1"
android:layout_width="246dp"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</LinearLayout>
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link]
package [Link].mypro71;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
@SuppressWarnings("unused")
publicclassMainActivityextends Activity
{
EditText et1,et2,et3;
ListViewlview;
SQLiteDatabase dbase;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
et1=(EditText)findViewById([Link].editText1);
et2=(EditText)findViewById([Link].editText2);
et3=(EditText)findViewById([Link].editText3);
lview=(ListView)findViewById([Link].listView1);
try
{
dbase=openOrCreateDatabase("Course",MODE_PRIVATE,null);
[Link]("create table if not exists creg(rnonumber,sname
varchar(50),course varchar(50))");
}
catch(Exception e)
{
[Link]([Link],
[Link](),Toast.LENGTH_SHORT).show();
}
}
publicvoidinsert(View v)
{
ContentValues cv=newContentValues();
[Link]("rno",[Link]().toString());
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link]("sname",[Link]().toString());
[Link]("course",[Link]().toString());
long status=[Link]("creg", null,cv);
if(status!=-1)
{
[Link]([Link], "Record
Inserted Successfully",Toast.LENGTH_SHORT).show();
[Link](" ");
[Link](" ");
[Link](" ");
read(v);
}
else
{
[Link]([Link], "no record
inserted",Toast.LENGTH_SHORT).show();
}
}
publicvoidread(View v)
{
Cursor c = [Link]("creg", null, null, null, null, null, null);
ArrayList<String> list = newArrayList<String>();
while([Link]())
{
String msg=[Link](0)+"|"+[Link](1)+"|"+[Link](2);
[Link](msg);
}
ArrayAdapter<String> adapter =new
ArrayAdapter<String>(this,[Link].simple_list_item_single_choice,list);
[Link](adapter);
}
publicvoidupdate(View v)
{
ContentValues cv=newContentValues();
[Link]("sname",[Link]().toString());
[Link]("course",[Link]().toString());
int status =[Link]("creg", cv, "rno=?", new
String[]{[Link]().toString()});
if(status>0)
{
[Link]([Link], "successfully
updated",Toast.LENGTH_SHORT).show();
}
else
{
[Link]([Link], "no
updated",Toast.LENGTH_SHORT).show();
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
}
publicvoiddelete(View v)
{
int status =[Link]("creg", "rno=?",new
String[]{[Link]().toString()});
if(status>0)
{
[Link]([Link], " Record
Deleted Successfully ",Toast.LENGTH_SHORT).show();
}
else
{
[Link]([Link],
"fail",Toast.LENGTH_SHORT).show();
}
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
returntrue;
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
8. EMAILING
Program:
activity_main.xml
<LinearLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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"
android:orientation="vertical">
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Mail id"
android:text="@string/et1">
<requestFocus />
</EditText>
<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Subject"
android:text="@string/et2" />
<EditText
android:id="@+id/et3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message"
android:text="@string/et3" />
<Button
android:id="@+id/attach"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:onClick="attach"
android:text="@string/btn1" />
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/smail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:onClick="send_mail"
android:text="@string/btn2" />
</LinearLayout>
</LinearLayout>
[Link]
package [Link].mypro8;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclassMainActivityextends Activity {
EditText et1,et2,et3;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
et1=(EditText)findViewById([Link].et1);
et2=(EditText)findViewById([Link].et2);
et3=(EditText)findViewById([Link].et3);
}
publicvoidattach(View v){
Intent i=newIntent();
[Link](Intent.ACTION_GET_CONTENT);
[Link]("*/*");
startActivityForResult(i,123);
}
Uri u;
@Override
protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) {
[Link](requestCode, resultCode, data);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
if(resultCode==RESULT_OK){
u=[Link]();
}
}
publicvoidsend_mail(View v)
{
String send=[Link]().toString();
String sub=[Link]().toString();
String body=[Link]().toString();
Intent i=newIntent();
[Link](Intent.ACTION_SEND);
[Link](Intent.EXTRA_EMAIL,new String[]{send});
[Link](Intent.EXTRA_SUBJECT,sub);
[Link](Intent.EXTRA_TEXT, body);
[Link](Intent.EXTRA_STREAM, u);
[Link]("message/rfc822");
try
{
startActivity([Link](i,"Select any Email Client"));
[Link](getApplicationContext(), "Email has been send
succefully", Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
[Link](getApplicationContext(), "Error to send Email"+e,
Toast.LENGTH_LONG).show();
}
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
returntrue;
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
9. TELEPHONY
Program:
activity_main.xml
<LinearLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:hint="Enter number"
android:text="@string/et1">
<requestFocus />
</EditText>
<Button
android:id="@+id/del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/del" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
<Button
android:id="@+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/call" />
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/save" />
<Button
android:id="@+id/clr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/clr" />
</LinearLayout>
</LinearLayout>
[Link]
package [Link].mypro9;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclassMainActivityextends Activity implementsOnClickListener
{
EditText phone;
String phnum=" ";
Button clrbtn,savebtn,delbtn,callbtn;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
phone=(EditText)findViewById([Link].et1);
clrbtn=(Button)findViewById([Link]);
callbtn=(Button)findViewById([Link]);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
savebtn=(Button)findViewById([Link]);
delbtn=(Button)findViewById([Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
switch([Link]())
{
[Link]:
[Link](" ");
break;
[Link]:
phnum=[Link]().toString();
Intent intent1= newIntent(Intent.ACTION_INSERT);
[Link]([Link].CONTENT_TYPE);
[Link]([Link],phnum);
startActivity(intent1);
break;
[Link]:
phnum=[Link]().toString();
Intent intent2= newIntent(Intent.ACTION_CALL);
[Link]([Link]("[Link]
startActivity(intent2);
break;
[Link]:
StringBuilder str = new StringBuilder([Link]().toString());
int n= [Link]();
[Link](n-1);
phnum=[Link]();
[Link](phnum);
break;
}
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
returntrue;
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Program:
activity_main.xml
<LinearLayoutxmlns:android="[Link]
xmlns:tools="[Link]
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"
android:orientation="vertical">
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:text="@string/et1">
<requestFocus />
</EditText>
<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message"
android:text="@string/et2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:onClick="sendSms"
android:text="@string/btn" />
</LinearLayout>
</LinearLayout>
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link]
package [Link].mypro10;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
@SuppressWarnings("unused")
publicclassMainActivityextends Activity {
EditText et1,et2;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
et1=(EditText)findViewById([Link].et1);
et2=(EditText)findViewById([Link].et2);
}
publicvoidsendSms(View v)
{
Intent smsIntent = newIntent(Intent.ACTION_VIEW);
[Link]([Link]("smsto:"));
[Link]("[Link]-dir/mms-sms");
[Link]("address" ,new String ([Link]().toString()));
[Link]("sms_body" , [Link]().toString());
try
{
startActivity(smsIntent);
finish();
}
catch ([Link] ex)
{
[Link]([Link],
"SMS faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
publicvoidfinish()
{
[Link]([Link],
"SMS Sended Successfully", Toast.LENGTH_SHORT).show();
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Program:
activity_main1.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
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=".MainActivity1">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Select Options"
android:textSize="20dp"
android:textStyle="bold" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="200sp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:divider="@android:color/black"
android:dividerHeight="2dp">
</ListView>
</RelativeLayout>
activity_main2.xml
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
android:layout_alignLeft="@+id/imageView1"
android:layout_below="@+id/gallery1"
android:layout_marginTop="22dp"
android:text="My Rating"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"/>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/ratingBar1"
android:layout_below="@+id/ratingBar1"
android:text="Submit" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button1"
android:layout_marginTop="35dp"
android:text="Result:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:text="Back" />
</RelativeLayout>
activity_main3.xml
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/cplus" />
<Gallery
android:id="@+id/gallery1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignLeft="@+id/textView1"
android:layout_centerVertical="true"
android:animationDuration="2000"
android:padding="10dp"
android:spacing="5dp"
android:unselectedAlpha="0.5" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Back" />
</LinearLayout>
[Link]
package [Link].ex6_f;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclass MainActivity1 extends Activity {
ListView lv;
TextView tv;
String[] item={"Rating_Bar","Gallery"};
ArrayAdapter<String> adapter;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main1);
lv=(ListView) findViewById([Link].listView1);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
adapter=new ArrayAdapter<String>(this,[Link].simple_list_item_1,item);
[Link](adapter);
[Link]([Link]() {
@Override
publicvoidonItemClick(AdapterView<?>aview, View v, int position,
long l) {
if([Link](position)=="Rating_Bar"){
Intent i=newIntent();
[Link](new
ComponentName(getApplicationContext(),[Link]));
startActivity(i);
}
else
{
Intent i1=newIntent();
[Link](new
ComponentName(getApplicationContext(),[Link]));
startActivity(i1);
}
}
});
}
}
[Link]
package [Link].ex6_f;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclass MainActivity2 extends Activity {
publicRatingBarrBar;
publicTextView tv;
public Button b,b1;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main2);
addListenerOnRatingBar();
addListenerOnButtonClick();
addListenerOnButtonClick2();
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
publicvoidaddListenerOnRatingBar() {
// TODO Auto-generated method stub
RatingBarrBar=(RatingBar) findViewById([Link].ratingBar1);
[Link]([Link](
){
@Override
publicvoidonRatingChanged(RatingBarratingBar, float rating,
booleanfromUser) {
// TODO Auto-generated method stub
[Link](getApplicationContext(),"Rating
is:"+rating,Toast.LENGTH_LONG).show();
}
});
}
publicvoidaddListenerOnButtonClick() {
// TODO Auto-generated method stub
b=(Button) findViewById([Link].button1);
finalRatingBarrBar=(RatingBar) findViewById([Link].ratingBar1);
finalTextViewrate_tv=(TextView) findViewById([Link].textView2);
[Link]([Link]() {
@Override
publicvoidonClick(View arg0) {
// TODO Auto-generated method stub
String rating=[Link]([Link]());
rate_tv.setText("Your Rating is:"+[Link](rating));
}
});
}
publicvoid addListenerOnButtonClick2() {
b1=(Button) findViewById([Link].button2);
[Link]([Link]() {
@Override
publicvoidonClick(View arg0) {
// TODO Auto-generated method stub
Intent i1=newIntent();
[Link](newComponentName(getApplicationContext(),[Link]
ass));
startActivity(i1);
}
});
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link]
package [Link].ex6_f;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
@SuppressWarnings("deprecation")
publicclass MainActivity3 extends Activity {
GallerysGallery;
publicCustomGalleryAdaptercgAdapter;
publicImageViewimgView;
public Button b;
int[] images={[Link],[Link],[Link]};
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main3);
sGallery=(Gallery) findViewById([Link].gallery1);
imgView=(ImageView) findViewById([Link].imageView1);
cgAdapter=newCustomGalleryAdapter(getApplicationContext(),images);
[Link](cgAdapter);
[Link]([Link]() {
@Override
publicvoidonItemClick(AdapterView<?>parent,Viewview,int
position,long id){
[Link](images[position]);
}
});
b=(Button) findViewById([Link].button1);
[Link]([Link]() {
@Override
publicvoidonClick(View arg0) {
// TODO Auto-generated method stub
Intent i1=newIntent();
[Link](new
ComponentName(getApplicationContext(),[Link]));
startActivity(i1);
}
});
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
[Link]
package [Link].ex6_f;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
@SuppressWarnings("deprecation")
publicclassCustomGalleryAdapterextendsBaseAdapter {
privatefinal Context context;
privatefinalint[] images;
publicCustomGalleryAdapter(Context c, int[] images) {
context = c;
[Link] = images;
}
// returns the number of images, in our example it is 10
publicintgetCount() {
[Link];
}
// returns the Item of an item, i.e. for our example we can get the image
public Object getItem(int position) {
return position;
}
// returns the ID of an item
publiclonggetItemId(int position) {
return position;
}
// returns an ImageView view
public View getView(int position, View convertView, ViewGroup parent) {
// position argument will indicate the location of image
// create a ImageView programmatically
ImageViewimageView = newImageView(context);
// set image in ImageView
[Link](images[position]);
// set ImageView param
[Link]([Link](200, 200));
returnimageView;
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
Output:
My Rating Bar
Gallery
Page No:
AAGAC Dept. of Information Technology