Create Android Application:
- File >> New >> Android Application
- Enter Project name: AlertDialogApp
- Package: com.ambilpursunil.newapp
- Keep other default selections, click Next until you reach Finish

1.Simply Copy and Past the Code which is display below in the MainActivity.java
package com.ambilpursunil.newapp;
import android.app.Activity;
import android.app.AlertDialog;
import
android.content.DialogInterface;
import android.os.Bundle;
public class MainActivity extends Activity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AlertDialog al = new AlertDialog.Builder(MainActivity.this).create();
al.setTitle("Pick
u..!");
al.setMessage("Cum
On Pick Up Dude..!");
al.setButton("Place
a Pin point ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface
dialog, int which)
{
// TODO Auto-generated method stub
}
});
al.setButton2("Cancle", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface
dialog, int which)
{
// TODO Auto-generated method stub
}
});
al.setButton3("Quit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface
dialog, int which)
{
// TODO Auto-generated method stub
}
});
al.show();
}
}
2.Simple Copy and Past the below code: actvitiy_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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.ambilpursunil.newapp.MainActivity"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wel come To Alert Dialog" />
</RelativeLayout>
3.Copy and past the code for manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ambilpursunil.newapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21"
/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When our application launch it will Alert with three buttons place a pin point, cancle, quit. click any one it will disappear.
Please Send Your Comments To ambilpura.sunil@gmail.com
Stay Tune For Next Tutorial... Check Box In Android:
No comments:
Post a Comment