Android examples for User Interface:Alert Dialog
build an alert dialog
//package com.java2s; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; public class Main { /**// ww w . ja va2s . com * 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(); } }