Professional Documents
Culture Documents
Pratical : 1 – Installation and setup of java development kit(JDK),setup android SDK,setup eclipse
IDE,setup android development tools (ADT) plugins,create android virtual device
Let's see the list of software required to setup android for eclipse IDE manually.
Install the JDK
For creating android application, JDK must be installed if you are developing the android
application with Java language. download the JDK
Download and install the Eclipse for developing android application
For developing the android application using eclipse IDE, you need to install the Eclipse. you can
download it from this location download the Eclipse. Eclipse classic version is recommended but
we are using the Eclipse IDE for JavaEE Developers.
Download and Install the android SDK
First of all, download the android SDK. In this example we have installed the android SDK for
windows (.exe version).
Now double click on the exe file, it will be installed. I am using the android 2.2 version here.
Intall the ADT plugin for eclipse
ADT (Android Development Tools) is required for developing the android application in the
eclipse IDE. It is the plugin for Eclipse IDE that is designed to provide the integrated
environment.
For downloading the ADT, you need to follow these steps:
Start the eclipse IDE, then select Help > Install new software...
In the work with combo box, write https://dl-ssl.google.com/android/eclipse/
select the checkbox next to Developer Tools and click next
You will see, a list of tools to be downloaded here, click next
click finish
After completing the installation, restart the eclipse IDE
Configure the ADT plugin
After the installing ADT plugin, now tell the eclipse IDE for your android SDK location. To do so:
Select the Window menu > preferences
Now select the android from the left panel. Here you may see a dialog box asking if you want
to send the statistics to the google. Click proceed.
Click on the browse button and locate your SDK directory e.g. my SDK location is C:\Program
Files\Android\android-sdk.
Click the apply button then OK.
Create the AVD
For running the android application in the Android Emulator, you need to create and AVD. For
creating the AVD:
Select the Window menu > AVD Manager
Click on the new button, to create the AVD
Now a dialog appears, write the AVD name e.g. myavd. Now choose the target android
version e.g. android2.2.
click the create AVD
Create the hello android application
Pratical : 2- Create “Hello World” application. That will display “Hello World” in the middle of the screen
using TextView Widget in the red color
Example 1
Step 1: (activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
Step 2: (MainActivity.java)
package com.example.helloexample;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.app.Activity;
import android.graphics.Color;
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name: " >
</TextView>
<EditText
android:id="@+id/txtUname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" >
</EditText>
</TableRow>
<TableRow>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password: " >
</TextView>
<EditText
android:id="@+id/txtPwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:text="" >
</EditText>
</TableRow>
<TableRow>
<Button
android:id="@+id/btnClear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Clear" >
</Button>
<Button
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login" >
</Button>
</TableRow>
</TableLayout>
Step 2: (MainActivity.java)
package com.example.disablebuttonlogin;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity
{
String uname="abc@gmail.com";
String pwd="rahul";
EditText txtUsr,txtPwd;
Button btnLogin,btnClear;
boolean usrStatus=false;
boolean pwdStatus=false;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnLogin= (Button) findViewById(R.id.btnLogin);
txtUsr = (EditText)findViewById(R.id.txtUname);
txtPwd = (EditText)findViewById(R.id.txtPwd);
btnLogin.setEnabled(false);
btnLogin.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(), "Valid UserName And Password",
Toast.LENGTH_LONG).show();
}
});
final Button btnClear = (Button)findViewById(R.id.btnClear);
btnClear.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
txtUsr.setText("");
txtPwd.setText("");
}
});
txtUsr.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
if(uname.equals(txtUsr.getText().toString()))
{
usrStatus=true;
}
else
{
usrStatus=false;
}
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3)
{
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable arg0)
{
}
});
txtPwd.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
// TODO Auto-generated method stub
if(pwd.equals(txtPwd.getText().toString()))
{
pwdStatus=true;
}
else
{
pwdStatus=false;
}
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3)
{
}
public void afterTextChanged(Editable arg0)
{
if(usrStatus && pwdStatus)
{
btnLogin.setEnabled(true);
}
else
{
btnLogin.setEnabled(false);
}
}
});
}
}
Pratical : 7 - Create and Login application as above. Validate login data and display Error to user using
setError() method.
Step 1: (activity_main.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="REGISTER USER"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#176CEC"
android:textStyle="bold" />
<EditText
android:id="@+id/editText_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:ems="10"
android:hint="YOUR EMAIL"
android:inputType="textEmailAddress"
android:padding="12dp" />
<EditText
android:id="@+id/editText_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:background="#fff"
android:ems="10"
android:hint="ENTER PASSWORD"
android:inputType="textPassword"
android:padding="12dp" />
<Button
android:id="@+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#176CEC"
android:text="SIGN UP"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textStyle="bold" />
</LinearLayout>
Step 2: (MainActivity.java)
package com.example.edittextvalidation;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
public class MainActivity extends Activity
{
private EditText emailEditText;
private EditText passEditText;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailEditText = (EditText) findViewById(R.id.editText_email);
passEditText = (EditText) findViewById(R.id.editText_password);
findViewById(R.id.btn_signup).setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
final String email = emailEditText.getText().toString();
if (!isValidEmail(email))
{
emailEditText.setError("Invalid Email");
}
}
});
}
private boolean isValidEmail(String email)
{
String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Pattern p1 = Pattern.compile(EMAIL_PATTERN);
Matcher m1 = p1.matcher(email);
return m1.matches();
}
<Button
android:id="@+id/button1"
android:text="Column 2" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF0000" />
<!-- edittext span 2 column -->
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >
<EditText
android:id="@+id/editText1"
android:layout_span="2"
android:text="Column 1 & 2" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF0000" />
<!-- display this button in 3rd column via layout_column(zero based) -->
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >
<Button
android:id="@+id/button4"
android:layout_column="2"
android:text="Column 3" />
</TableRow>
</TableLayout>
Pratical: 9 -Create an application for demonstration of Relative and Table Layout in android
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 2"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 3"
/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 4"
/>
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 5"
/>
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 6"
/>
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 7"
/>
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 8"
/>
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 9"
/>
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Button 10"
/>
</LinearLayout>
</ScrollView>
Pratical: 10 -Create an application for demonstration of Explicitly Starting New Activity using Intent.
Step:-1(Androidmanifest.xml)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/title_activity_main"
></activity>
</application>
</manifest>
Step:-2(activity_main.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="perform"
android:text="Click" />
</LinearLayout>
Step:-3(second.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Helloword" />
</LinearLayout>
Step:-4(MainActivity.java)
package com.example.eexample;
import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.content.Intent;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void perform(View v)
{
Intent i1=new Intent(MainActivity.this,SecondActivity.class);
startActivity(i1);
}
}
Step:-5(SecondActivity.java)
package com.example.eexample;
import android.app.Activity;
import android.os.Bundle;
public class SecondActivity extends Activity
{
public void onCreate(Bundle b1)
{
super.onCreate(b1);
setContentView(R.layout.second);
}
}
Pratical :11 - Create an application that will pass two number using TextView to the next screen , and on
the next screen display sum of that number
Step:-1(Androidmanifest.xml)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.impexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SActivity"></activity>
</application>
</manifest>
Step:-2(activity_main.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter the Number 1" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter the Number 2" />
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Perform"
android:text="Sum" />
</LinearLayout>
Step:-3(second.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number1" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number2" />
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer" />
</LinearLayout>
Step:-4(MainActivity.java)
package com.example.impexample;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.app.Activity;
import android.content.Intent;
}
}
Step:-5(SActivity.java)
package com.example.impexample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
Step:-2(activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout">
<Spinner
android:id="@+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/color_arrays"
android:prompt="@string/color_prompt"
/>
</RelativeLayout>
Step:-3(MainActivity.java)
package com.example.changecolor;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.app.Activity;
import android.graphics.Color;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
public class MainActivity extends Activity implements OnItemSelectedListener
{
Spinner spin;
RelativeLayout rl;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spin=(Spinner) findViewById(R.id.spinner1);
rl = (RelativeLayout) findViewById(R.id.main_layout);
spin.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView arg0, View arg1, int arg2,long arg3)
{
// TODO Auto-generated method stub
String name=spin.getSelectedItem().toString();
if(name.equals("Red"))
rl.setBackgroundColor(Color.RED);
else if(name.equals("Blue"))
rl.setBackgroundColor(Color.BLUE);
else if(name.equals("Green"))
rl.setBackgroundColor(Color.GREEN);
}
public void onNothingSelected(AdapterView arg0)
{
// TODO Auto-generated method stub
}
}
Pratical: 13 -Create an application that will get the Text Entered in Edit Text and display that Text using
toast (Message).
Step:-1(activity_main.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EditText Event Example" />
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Your Name" >
<requestFocus />
</EditText>
</LinearLayout>
Step:-2(MainActivity.java)
package com.example.pthirteenexample;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.Toast;
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
String s=et1.getText().toString();
Toast.makeText(getBaseContext(), s, Toast.LENGTH_SHORT).show();
}
}
});
}
}
Pratical: 14 -Create an application that will Demonstrate Button onClick() Event and change the TextView
Color based on button Clicked
step:-1(activity_main.xml)
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/AbsoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="37dp"
android:layout_y="52dp"
android:text="Red" />
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="37dp"
android:layout_y="21dp"
android:text="Text View Change the BackGround Color" />
<Button
android:id="@+id/bt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="212dp"
android:layout_y="51dp"
android:text="Green" />
<Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="120dp"
android:layout_y="54dp"
android:text="Blue" />
</AbsoluteLayout>
Step:-2(Mainactivity.java)
package com.example.pfourteenexample;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.graphics.Color;
}
public void onClick(View v)
{
switch(v.getId())
{
case R.id.bt1:
tv1.setBackgroundColor(Color.RED);
tv1.setTextColor(Color.CYAN);
break;
case R.id.bt2:
tv1.setBackgroundColor(Color.BLUE);
tv1.setTextColor(Color.WHITE);
break;
case R.id.bt3:
tv1.setBackgroundColor(Color.GREEN);
tv1.setTextColor(Color.MAGENTA);
break;
default:
tv1.setBackgroundColor(Color.BLACK);
break;
}
}
}
Pratical: 15 -Create an UI such that, one screen have list of all the types of cars. On selecting of any car
name, next screen should show Car details like: name, launched date, company name
step:-1(string.xml)
<resources>
<string name="app_name">carproject</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">Car</string>
<string-array name="car">
<item>alto</item>
<item>hundi</item>
<item>oodi</item>
</string-array>
</resources>
step:-2(activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/car"/>
</RelativeLayout>
Step:-3(Mainactivity.java)
package com.example.carproject;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class MainActivity extends Activity implements OnItemClickListener {
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView) findViewById(R.id.listView1);
lv.setOnItemClickListener(this);
}
public void onItemClick(AdapterView arg0, View arg1, int pos, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(this, pos + " click", Toast.LENGTH_SHORT).show();
step:-4(details.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textViewdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textViewcompanyname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
step:-5(DetailsActivity.java)
package com.example.carproject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class DetailsActivity extends Activity
{
TextView tvname,tvdate,tvcompanyname;
int id=0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
tvname=(TextView) findViewById(R.id.textViewname);
tvdate=(TextView) findViewById(R.id.textViewdate);
tvcompanyname=(TextView) findViewById(R.id.textViewcompanyname);
Intent myintent=getIntent();
id=myintent.getIntExtra("id", 0);
if(id==0)
{
tvname.setText("maruti suzuki");
tvdate.setText("1-12-1987");
tvcompanyname.setText("Maruti");
}
if(id==1)
{
tvname.setText("hundai i10");
tvdate.setText("2-12-1987");
tvcompanyname.setText("Hundai");
}
if(id==2)
{
tvname.setText("oodi");
tvdate.setText("1-10-1993");
tvcompanyname.setText("Oodi");
}
}
}
step:-6(Androidmanifest.xml)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.carproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Details">
</activity>
</application>
</manifest>
Pratical: 16 -Create an application that will Demonstrate Dialog Box Control In Android
Step 1: (activity_main.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show Alert With Three Button" />
</LinearLayout>
Step 2: (MainActivity.java)
package com.example.AlertDialogexample;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
Step:2 (activity_main.xml)
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:stretchColumns="0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="@string/title"
android:layout_x="110dp"
android:layout_y="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:text="@string/roll_no"
android:layout_x="30dp"
android:layout_y="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editRollno"
android:inputType="number"
android:layout_x="150dp"
android:layout_y="50dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<TextView android:text="@string/name"
android:layout_x="30dp"
android:layout_y="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editName"
android:inputType="text"
android:layout_x="150dp"
android:layout_y="100dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<TextView android:text="@string/marks"
android:layout_x="30dp"
android:layout_y="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editMarks"
android:inputType="number"
android:layout_x="150dp"
android:layout_y="150dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnAdd"
android:text="@string/add"
android:layout_x="30dp"
android:layout_y="200dp"
android:layout_width="100dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnDelete"
android:text="@string/delete"
android:layout_x="150dp"
android:layout_y="200dp"
android:layout_width="100dp"
android:layout_height="40dp"/>n
<Button android:id="@+id/btnModify"
android:text="@string/modify"
android:layout_x="30dp"
android:layout_y="250dp"
android:layout_width="100dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnView"
android:text="@string/view"
android:layout_x="150dp"
android:layout_y="250dp"
android:layout_width="100dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnViewAll"
android:text="@string/view_all"
android:layout_x="30dp"
android:layout_y="300dp"
android:layout_width="100dp"
android:layout_height="40dp"/>
<Button
android:id="@+id/btnShowInfo"
android:layout_width="186dp"
android:layout_height="wrap_content"
android:layout_x="80dp"
android:layout_y="352dp"
android:text="@string/show_info" />
</AbsoluteLayout>
Step:3 (MainActivity.java)
package com.example.sqlex;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;