Alert Dialog Android
Aler Dialog Android
Hi friends today we will se how to create simple alert dialog in Android.
Its very simple , we can create alert dailog with 1 , 2 or 3 buttons
here is sample code.
Hi friends today we will se how to create simple alert dialog in Android.
Its very simple , we can create alert dailog with 1 , 2 or 3 buttons
here is sample code.
packagecom.example.dailogboxexample;
importandroid.app.Activity;
importandroid.app.AlertDialog;
importandroid.content.Context;
importandroid.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
importandroid.view.View.OnClickListener;
import android.widget.Button;
importandroid.widget.Toast;
public class MainActivity extends Activity {
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(context)
.setTitle("Alert Box ")
.setMessage(
"Please check your Internet conection, and try again?")
.setPositiveButton("Ok",
newDialogInterface.OnClickListener() {
public voidonClick(DialogInterface dialog,
int which) {
Toast.makeText(context, "Ok Pressed", 1)
.show();
}
}).show();
}
});
Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(context)
.setTitle("Alert Box ")
.setMessage(
"Please check your Internet conection, and try again?")
.setPositiveButton("Yes",
newDialogInterface.OnClickListener() {
public voidonClick(DialogInterface dialog,
int which) {
Toast.makeText(context, "Yes Pressed",
 
visit link download
Comments
Post a Comment