build a alert dialog - Android android.app

Android examples for android.app:AlertDialog

Description

build a alert dialog

Demo Code

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class Main{

    /**/*from   ww  w  .j  a v a  2  s  .  co  m*/
     * 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();
    }

}

Related Tutorials