Android examples for User Interface:Alert Dialog
show a system default alert dialog with given title, msg, ok, cancel, listeners
//package com.java2s; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; public class Main { /**/* w w w . j av a2 s. c o m*/ * show an system default alert dialog with given title, msg, ok, cancel, listeners * * @param context * @param title * @param msg * @param ok * @param cancel * @param lOk * @param lCancel */ public static void showAlert(Context context, int title, int msg, int ok, int cancel, DialogInterface.OnClickListener lOk, DialogInterface.OnClickListener lCancel) { AlertDialog dialog = buildAlert(context, title, msg, ok, cancel, lOk, lCancel); if (dialog != null) { dialog.show(); } } /** * show an system default alert dialog with given title, msg, ok, cancal, listeners * * @param context * @param title * @param msg * @param ok * @param cancel * @param lOk * @param lCancel */ public static void showAlert(Context context, CharSequence title, CharSequence msg, CharSequence ok, CharSequence cancel, DialogInterface.OnClickListener lOk, DialogInterface.OnClickListener lCancel) { AlertDialog dialog = buildAlert(context, title, msg, ok, cancel, lOk, lCancel); if (dialog != null) { dialog.show(); } } /** * show an system default alert dialog with given title, msg, ok, cancal, listeners * * @param context * @param title * @param msg * @param ok * @param lOk */ public static void showAlert(Context context, CharSequence title, CharSequence msg, CharSequence ok, DialogInterface.OnClickListener lOk) { AlertDialog dialog = buildAlert(context, title, msg, ok, null, lOk, null); if (dialog != null) { dialog.show(); } } /** * build a alert dialog * * @param context * @param title * @param msg * @param ok * @param cancel * @param lOk * @param lCancel * @return */ public static AlertDialog buildAlert(Context context, Integer title, Integer msg, Integer ok, Integer cancel, DialogInterface.OnClickListener lOk, DialogInterface.OnClickListener lCancel) { AlertDialog.Builder builder = new AlertDialog.Builder(context); if (title != null) builder.setTitle(title); if (msg != null) builder.setMessage(msg); if (ok != null) builder.setPositiveButton(ok, lOk); if (cancel != null) builder.setNegativeButton(cancel, lCancel); return builder.create(); } /** * build a alert dialog * * @param context * @param title * @param msg * @param ok * @param cancel * @param lOk * @param lCancel * @return */ public static AlertDialog buildAlert(Context context, CharSequence title, CharSequence msg, CharSequence ok, CharSequence cancel, DialogInterface.OnClickListener lOk, DialogInterface.OnClickListener lCancel) { AlertDialog.Builder builder = new AlertDialog.Builder(context); if (title != null) builder.setTitle(title); if (msg != null) builder.setMessage(msg); if (ok != null) builder.setPositiveButton(ok, lOk); if (cancel != null) builder.setNegativeButton(cancel, lCancel); return builder.create(); } }