Yes/No dialog

Yes/No dialog

This code shows a yes/no dialog as pop-up. The code can handle the response.


DialogInterface.OnClickListener dialogClickListener = 
  new DialogInterface.OnClickListener() {

  public void onClick(DialogInterface dialog, int which) {
    switch (which){
      case DialogInterface.BUTTON_POSITIVE:
        // On click YES button

      case DialogInterface.BUTTON_NEGATIVE:
        // On click NO button

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Is this a yes-no dialog?")
  .setPositiveButton("Yes", dialogClickListener)
  .setNegativeButton("No", dialogClickListener)