How to display an AlertDialog in your Android application
SDK Version:
M3 Here is an example of an applacation, that illustrates how you can create a simple AlertDialog. The dialog can display maximum three buttons.

First of all declarate the AlertDialog type object:
- AlertDialog alertDialog = new AlertDialog.Builder(Main.this).create();
Main.this is my activity's context.
You can set your dialog's title like this:
- alertDialog.setTitle("Reset...");
And a message:
- alertDialog.setMessage("R u sure?");
Next thing, set your button(s) functions:
- alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- //here you can add functions
- } });
And you can change the icon of your AlertDialog using this line:
- alertDialog.setIcon(R.drawable.icon);
Last thing, don't forget to show your dialog:
- alertDialog.show();




