Home » Labs » Display Yes/No Dialog Box in Android – AlertDialog.Builder  

Display Yes/No Dialog Box in Android – AlertDialog.Builder

Filed under Labs

If you want to show a Yes/No Dialog Box in Android then you use the following method. You can learn more about AlertDialog.Builder y visiting this link.Courtesy- stackoverflow.com

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        switch (which){
        case DialogInterface.BUTTON_POSITIVE:
            //Yes button clicked
        case DialogInterface.BUTTON_NEGATIVE:
            //No button clicked
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
    .setNegativeButton("No", dialogClickListener).show();

Posts you may like: