Android – Alert Dialog


public void showAlertDialog(){
 AlertDialog.Builder dialog = new AlertDialog.Builder(this); // initialize an alert dialog
 dialog.setTitle("here is title"); // set the title for alert dialog
 dialog.setMessage("here is message"); // set messages...
 dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { // set OK button for alert dialog
 @Override
 public void onClick(DialogInterface dialog, int which) {
 Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show();
 // or do something here !!!
 }
 });
 dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { // set cancel button
 @Override
 public void onClick(DialogInterface dialog, int which) {
 Toast.makeText(getBaseContext(), "Cancelled", Toast.LENGTH_SHORT).show();
 }
 });
 dialog.create().show(); // remember!!!
}

Advertisements

One thought on “Android – Alert Dialog

  1. Pingback: Table of contents | David Ng

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s