Java tutorial
//package com.java2s; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; public class Main { /** * Creates a confirmation dialog with Yes-No Button. By default the buttons just dismiss the * dialog. * * @param ctx * @param message Message to be shown in the dialog. * @param yesListener Yes click handler * @param noListener ** */ public static void showConfirmDialog(Context ctx, String message, DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener) { showConfirmDialog(ctx, message, yesListener, noListener, "Yes", "No"); } /** * Creates a confirmation dialog with Yes-No Button. By default the buttons just dismiss the * dialog. * * @param ctx * @param message Message to be shown in the dialog. * @param yesListener Yes click handler * @param noListener * @param yesLabel Label for yes button * @param noLabel Label for no button * */ public static void showConfirmDialog(Context ctx, String message, DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener, String yesLabel, String noLabel) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); if (yesListener == null) { yesListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }; } if (noListener == null) { noListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }; } builder.setMessage(message).setPositiveButton(yesLabel, yesListener).setNegativeButton(noLabel, noListener) .show(); } }