Android examples for User Interface:Alert Dialog
display Alert dialog with OK Cancel button
//package com.java2s; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; public class Main { public static final String OK = "OK"; public static final String CANCEL = "Cancel"; private static final DialogInterface.OnClickListener DISMISSER = new DialogInterface.OnClickListener() { @Override//from w w w . j a v a 2 s . co m public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }; public static void displayAlertOKCancel(Context context, String alertTitle, String alertMessage, DialogInterface.OnClickListener okListener) { AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.setTitle(alertTitle); alertDialog.setMessage(alertMessage); alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, OK, okListener); alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, CANCEL, DISMISSER); alertDialog.show(); } }