AlertDialog yes no – Alert – Messagebox – Android sample

Dialog Yes No sample code

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit application?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                MyActivity.this.finish(); //Close  this Activity for example: MyActivity.java
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                // some code if you want
                dialog.cancel();
           }
       });
AlertDialog alert = builder.create();
alert.show();
This entry was posted in Android Examples Code and tagged , . Bookmark the permalink.


Comments are closed.



8,186 views