Sdplab
Sdplab
Sdplab
Program:
activity_main.xml
<RelativeLayoutxmlns: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" >
<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>
MainActivity.java
packagecom.example. mypro1;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.TextView;
publicclassMainActivityextends Activity
{
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b=(Button)findViewById(R.id.btn);
b.setOnClickListener(newView.OnClickListener()
{
@Override
publicvoidonClick(View v)
{
EditText et=(EditText)findViewById(R.id.txt);
TextView tv=(TextView)findViewById(R.id.tv2);
tv.setText(et.getText());
}
});
}
}
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="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="104dp"
android:layout_marginTop="142dp"
android:onClick="next"
android:text="@string/next" />
</RelativeLayout>
activity_main1.xml
<RelativeLayoutxmlns: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" >
<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
MainActivity.java
package com.example.mypro2;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.ComponentName;
importandroid.content.Intent;
importandroid.view.Menu;
importandroid.view.View;
publicclassMainActivityextends Activity
{
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
publicvoidnext(View v)
{
Intent i=newIntent();
i.setComponent(newComponentName(this, Welcome.class));
startActivity(i);
}
}
Welcome.java
package com.example.mypro2;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
publicclass Welcome extends Activity
{
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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="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">
<fragment
android:id="@+id/fragment2"
android:name="com.example. 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="com.example. mypro3.Fragment1"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="22dp" />
</RelativeLayout>
fragment1.xml
<FrameLayoutxmlns: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="#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>
fragment2.xml
<FrameLayoutxmlns: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="#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>
MainActivity.java
package com.example.mypro3;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
import android.support.v4.app.Fragment;
@SuppressWarnings("unused")
publicclassMainActivityextends Activity {
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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(R.menu.main, menu);
returntrue;
}
}
Fragment1.java
packagecom.example.mypro3;
importandroid.app.Fragment;
importandroid.os.Bundle;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
publicclass Fragment1 extends Fragment
{
@Override
public View onCreateView(LayoutInflaterinflater,ViewGroupcontainer,Bundle
savedInstanceState)
{
returninflater.inflate(R.layout.fragment1,container,false);
}
}
Fragment2.java
package com.example.mypro3;
importandroid.app.Fragment;
importandroid.os.Bundle;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
publicclass Fragment2 extends Fragment
{
@Override
public View onCreateView(LayoutInflaterinflater,ViewGroupcontainer,Bundle
savedInstanceState)
{
returninflater.inflate(R.layout.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="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">
<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>
MainActivity.java
package com.example.mypro4;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.view.View;
importandroid.view.View.OnClickListener;
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.RadioButton;
importandroid.widget.RadioGroup;
importandroid.widget.RadioGroup.OnCheckedChangeListener;
importandroid.widget.TextView;
importandroid.widget.Toast;
publicclassMainActivityextends Activity
{
privateRadioGroupradioGroup;
@SuppressWarnings("unused")
privateRadioButtonmale,female,tgen;
privateEditText name;
private Button btn;
privateTextView tv;
@Override
protectedvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup=(RadioGroup) findViewById(R.id.MyradioGroup);
radioGroup.setOnCheckedChangeListener(new
OnCheckedChangeListener()
{
@Override
publicvoidonCheckedChanged(RadioGroup group , int checked) {
// TODO Auto-generated method stub
if(checked==R.id.rb)
{
Toast.makeText(getApplicationContext(),
"choice: Male",Toast.LENGTH_SHORT).show();
}
elseif(checked == R.id.rb1)
{
Toast.makeText(getApplicationContext(), "choice:
Female",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "choice:
others",Toast.LENGTH_SHORT).show();
}
}
});
name=(EditText) findViewById(R.id.txt);
male=(RadioButton)findViewById(R.id.rb);
female=(RadioButton)findViewById(R.id.rb1);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
tgen=(RadioButton)findViewById(R.id.rb2);
tv=(TextView)findViewById(R.id.tv2);
btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v)
{
// TODO Auto-generated method stub
intselectedId = radioGroup.getCheckedRadioButtonId();
if(selectedId == male.getId())
{
tv.setText("Given Details are \n
name:"+name.getText()+" Gender: Male");
}
elseif(selectedId == female.getId())
{
tv.setText("Given Details are \n
name:"+name.getText()+" Gender: Female");
}
else
{
tv.setText("Given Details are \n
name:"+name.getText()+" Gender: Others");
}
}
});
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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="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"
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
MainActivity.java
package com.example.myproo55;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Menu;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.CheckBox;
importandroid.widget.ImageButton;
importandroid.widget.Toast;
publicclassMainActivityextends Activity {
CheckBox ch1,ch2,ch3;
Button buttonOrder;
ImageButton imgbtn1,imgbtn2,imgbtn3;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
privatevoidaddListenerOnButtonClick() {
// TODO Auto-generated method stub
ch1=(CheckBox)findViewById(R.id.checkBox1);
ch2=(CheckBox)findViewById(R.id.checkBox2);
ch3=(CheckBox)findViewById(R.id.checkBox3);
buttonOrder=(Button)findViewById(R.id.toggleButton1);
imgbtn1=(ImageButton)findViewById(R.id.imageButton1);
imgbtn2=(ImageButton)findViewById(R.id.imageButton2);
imgbtn3=(ImageButton)findViewById(R.id.imageButton3);
buttonOrder.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
inttotalamount=0;
StringBuilder result=newStringBuilder();
result.append("Selected Items:");
if(ch1.isChecked())
{
result.append("\nApple 100Rs");
totalamount+=100;
}
if(ch2.isChecked())
{
result.append("\nMango 50Rs");
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
totalamount+=50;
}
if(ch3.isChecked()){
result.append("\nOrange 120Rs");
totalamount+=120;
}
result.append("\nTotal: "+totalamount+"Rs");
//Displaying the message on the toast
Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
}
});
imgbtn1.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Selected Apple",
Toast.LENGTH_LONG).show();
}
});
imgbtn2.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Selected
Mango", Toast.LENGTH_LONG).show();
}
});
imgbtn3.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(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="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"
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
MainActivity.java
package com.example.mypro71;
importjava.util.ArrayList;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.ContentValues;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.database.Cursor;
importandroid.database.sqlite.SQLiteDatabase;
importandroid.view.Menu;
importandroid.view.View;
importandroid.widget.ArrayAdapter;
importandroid.widget.EditText;
importandroid.widget.ListView;
importandroid.widget.Toast;
importjava.util.List;
@SuppressWarnings("unused")
publicclassMainActivityextends Activity
{
EditText et1,et2,et3;
ListViewlview;
SQLiteDatabase dbase;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText)findViewById(R.id.editText1);
et2=(EditText)findViewById(R.id.editText2);
et3=(EditText)findViewById(R.id.editText3);
lview=(ListView)findViewById(R.id.listView1);
try
{
dbase=openOrCreateDatabase("Course",MODE_PRIVATE,null);
dbase.execSQL("create table if not exists creg(rnonumber,sname
varchar(50),course varchar(50))");
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,
e.toString(),Toast.LENGTH_SHORT).show();
}
}
publicvoidinsert(View v)
{
ContentValues cv=newContentValues();
cv.put("rno",et1.getText().toString());
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
cv.put("sname",et2.getText().toString());
cv.put("course",et3.getText().toString());
long status=dbase.insert("creg", null,cv);
if(status!=-1)
{
Toast.makeText(MainActivity.this, "Record
Inserted Successfully",Toast.LENGTH_SHORT).show();
et1.setText(" ");
et2.setText(" ");
et3.setText(" ");
read(v);
}
else
{
Toast.makeText(MainActivity.this, "no record
inserted",Toast.LENGTH_SHORT).show();
}
}
publicvoidread(View v)
{
Cursor c = dbase.query("creg", null, null, null, null, null, null);
ArrayList<String> list = newArrayList<String>();
while(c.moveToNext())
{
String msg=c.getInt(0)+"|"+c.getString(1)+"|"+c.getString(2);
list.add(msg);
}
ArrayAdapter<String> adapter =new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice,list);
lview.setAdapter(adapter);
}
publicvoidupdate(View v)
{
ContentValues cv=newContentValues();
cv.put("sname",et2.getText().toString());
cv.put("course",et3.getText().toString());
int status =dbase.update("creg", cv, "rno=?", new
String[]{et1.getText().toString()});
if(status>0)
{
Toast.makeText(MainActivity.this, "successfully
updated",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "no
updated",Toast.LENGTH_SHORT).show();
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
}
publicvoiddelete(View v)
{
int status =dbase.delete("creg", "rno=?",new
String[]{et1.getText().toString()});
if(status>0)
{
Toast.makeText(MainActivity.this, " Record
Deleted Successfully ",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this,
"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(R.menu.main, 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="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"
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>
MainActivity.java
package com.example.mypro8;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.view.Menu;
importandroid.view.View;
importandroid.widget.EditText;
importandroid.widget.Toast;
publicclassMainActivityextends Activity {
EditText et1,et2,et3;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText)findViewById(R.id.et1);
et2=(EditText)findViewById(R.id.et2);
et3=(EditText)findViewById(R.id.et3);
}
publicvoidattach(View v){
Intent i=newIntent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(i,123);
}
Uri u;
@Override
protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
if(resultCode==RESULT_OK){
u=data.getData();
}
}
publicvoidsend_mail(View v)
{
String send=et1.getText().toString();
String sub=et2.getText().toString();
String body=et3.getText().toString();
Intent i=newIntent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL,new String[]{send});
i.putExtra(Intent.EXTRA_SUBJECT,sub);
i.putExtra(Intent.EXTRA_TEXT, body);
i.putExtra(Intent.EXTRA_STREAM, u);
i.setType("message/rfc822");
try
{
startActivity(Intent.createChooser(i,"Select any Email Client"));
Toast.makeText(getApplicationContext(), "Email has been send
succefully", Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(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(R.menu.main, 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="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"
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>
MainActivity.java
package com.example.mypro9;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.view.Menu;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.provider.ContactsContract;
publicclassMainActivityextends Activity implementsOnClickListener
{
EditText phone;
String phnum=" ";
Button clrbtn,savebtn,delbtn,callbtn;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phone=(EditText)findViewById(R.id.et1);
clrbtn=(Button)findViewById(R.id.clr);
callbtn=(Button)findViewById(R.id.call);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
savebtn=(Button)findViewById(R.id.save);
delbtn=(Button)findViewById(R.id.del);
clrbtn.setOnClickListener(this);
savebtn.setOnClickListener(this);
delbtn.setOnClickListener(this);
callbtn.setOnClickListener(this);
}
@Override
publicvoidonClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
caseR.id.clr:
phone.setText(" ");
break;
caseR.id.save:
phnum=phone.getText().toString();
Intent intent1= newIntent(Intent.ACTION_INSERT);
intent1.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent1.putExtra(ContactsContract.Intents.Insert.PHONE,phnum);
startActivity(intent1);
break;
caseR.id.call:
phnum=phone.getText().toString();
Intent intent2= newIntent(Intent.ACTION_CALL);
intent2.setData(Uri.parse("tel:"+phnum));
startActivity(intent2);
break;
caseR.id.del:
StringBuilder str = new StringBuilder(phone.getText().toString());
int n= str.length();
str.deleteCharAt(n-1);
phnum=str.toString();
phone.setText(phnum);
break;
}
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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="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"
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
MainActivity.java
package com.example.mypro10;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.view.Menu;
importandroid.view.View;
importandroid.widget.EditText;
importandroid.widget.Toast;
importandroid.telephony.SmsManager;
importandroid.app.PendingIntent;
@SuppressWarnings("unused")
publicclassMainActivityextends Activity {
EditText et1,et2;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText)findViewById(R.id.et1);
et2=(EditText)findViewById(R.id.et2);
}
publicvoidsendSms(View v)
{
Intent smsIntent = newIntent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address" ,new String (et1.getText().toString()));
smsIntent.putExtra("sms_body" , et2.getText().toString());
try
{
startActivity(smsIntent);
finish();
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(MainActivity.this,
"SMS faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
publicvoidfinish()
{
Toast.makeText(MainActivity.this,
"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="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: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>
MainActivity1.java
package com.example.ex6_f;
importandroid.app.Activity;
importandroid.content.ComponentName;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.AdapterView;
importandroid.widget.ArrayAdapter;
importandroid.widget.ListView;
importandroid.widget.TextView;
publicclass MainActivity1 extends Activity {
ListView lv;
TextView tv;
String[] item={"Rating_Bar","Gallery"};
ArrayAdapter<String> adapter;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
lv=(ListView) findViewById(R.id.listView1);
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,item);
lv.setAdapter(adapter);
lv.setOnItemClickListener(newAdapterView.OnItemClickListener() {
@Override
publicvoidonItemClick(AdapterView<?>aview, View v, int position,
long l) {
if(adapter.getItem(position)=="Rating_Bar"){
Intent i=newIntent();
i.setComponent(new
ComponentName(getApplicationContext(),MainActivity2.class));
startActivity(i);
}
else
{
Intent i1=newIntent();
i1.setComponent(new
ComponentName(getApplicationContext(),MainActivity3.class));
startActivity(i1);
}
}
});
}
}
MainActivity2.java
package com.example.ex6_f;
importandroid.app.Activity;
importandroid.content.ComponentName;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.RatingBar;
importandroid.widget.TextView;
importandroid.widget.Toast;
publicclass MainActivity2 extends Activity {
publicRatingBarrBar;
publicTextView tv;
public Button b,b1;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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(R.id.ratingBar1);
rBar.setOnRatingBarChangeListener(newRatingBar.OnRatingBarChangeListener(
){
@Override
publicvoidonRatingChanged(RatingBarratingBar, float rating,
booleanfromUser) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"Rating
is:"+rating,Toast.LENGTH_LONG).show();
}
});
}
publicvoidaddListenerOnButtonClick() {
// TODO Auto-generated method stub
b=(Button) findViewById(R.id.button1);
finalRatingBarrBar=(RatingBar) findViewById(R.id.ratingBar1);
finalTextViewrate_tv=(TextView) findViewById(R.id.textView2);
b.setOnClickListener(newView.OnClickListener() {
@Override
publicvoidonClick(View arg0) {
// TODO Auto-generated method stub
String rating=String.valueOf(rBar.getRating());
rate_tv.setText("Your Rating is:"+String.valueOf(rating));
}
});
}
publicvoid addListenerOnButtonClick2() {
b1=(Button) findViewById(R.id.button2);
b1.setOnClickListener(newView.OnClickListener() {
@Override
publicvoidonClick(View arg0) {
// TODO Auto-generated method stub
Intent i1=newIntent();
i1.setComponent(newComponentName(getApplicationContext(),MainActivity1.cl
ass));
startActivity(i1);
}
});
}
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
MainActivity3.java
package com.example.ex6_f;
importandroid.app.Activity;
importandroid.content.ComponentName;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.AdapterView;
importandroid.widget.Button;
importandroid.widget.Gallery;
importandroid.widget.ImageView;
@SuppressWarnings("deprecation")
publicclass MainActivity3 extends Activity {
GallerysGallery;
publicCustomGalleryAdaptercgAdapter;
publicImageViewimgView;
public Button b;
int[] images={R.drawable.cplus,R.drawable.java,R.drawable.js};
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
sGallery=(Gallery) findViewById(R.id.gallery1);
imgView=(ImageView) findViewById(R.id.imageView1);
cgAdapter=newCustomGalleryAdapter(getApplicationContext(),images);
sGallery.setAdapter(cgAdapter);
sGallery.setOnItemClickListener(newAdapterView.OnItemClickListener() {
@Override
publicvoidonItemClick(AdapterView<?>parent,Viewview,int
position,long id){
imgView.setImageResource(images[position]);
}
});
b=(Button) findViewById(R.id.button1);
b.setOnClickListener(newView.OnClickListener() {
@Override
publicvoidonClick(View arg0) {
// TODO Auto-generated method stub
Intent i1=newIntent();
i1.setComponent(new
ComponentName(getApplicationContext(),MainActivity1.class));
startActivity(i1);
}
});
}
Page No:
AAGAC Dept. of Information Technology
Smart Device Programming Lab
CustomGalleryAdapter.java
package com.example.ex6_f;
importandroid.content.Context;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.BaseAdapter;
importandroid.widget.Gallery;
importandroid.widget.ImageView;
@SuppressWarnings("deprecation")
publicclassCustomGalleryAdapterextendsBaseAdapter {
privatefinal Context context;
privatefinalint[] images;
publicCustomGalleryAdapter(Context c, int[] images) {
context = c;
this.images = images;
}
// returns the number of images, in our example it is 10
publicintgetCount() {
returnimages.length;
}
// 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
imageView.setImageResource(images[position]);
// set ImageView param
imageView.setLayoutParams(newGallery.LayoutParams(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