Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:Main.java

public static void showAlertDialog(Context context, String title, String message, int iconId,
        String textButton) {//from  w w w. j a  v  a 2 s . co m

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.setCancelable(false);
    if (iconId > 0)
        builder.setIcon(iconId);

    builder.setNegativeButton(textButton, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:Main.java

static void showDialog(final Context context, String title, String message, final boolean isFinish) {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    alertDialogBuilder.setTitle(title);//from   w w w  . jav  a  2 s  .c  o  m

    // set dialog message
    alertDialogBuilder.setCancelable(false).setMessage(message).setPositiveButton(android.R.string.ok,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                    if (isFinish)
                        ((Activity) context).finish();
                }
            });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();

}

From source file:Main.java

public static void showMessage(Context _context, String title, String message, int icon,
        DialogInterface.OnClickListener ackHandler) {
    try {/*from   w w  w.  jav  a  2s . com*/
        AlertDialog.Builder builder = new AlertDialog.Builder(_context);
        builder.setTitle(title);
        builder.setMessage(Html.fromHtml(message));
        builder.setCancelable(false);
        builder.setPositiveButton("Acknowledged", ackHandler);
        builder.setIcon(icon);
        builder.show();
    } catch (Exception e) {
    }
}

From source file:Main.java

/**
 * showInformationDialog//from w  w  w  . j  a v  a2 s.c  o  m
 *
 * @param title
 * @param message
 * @param context
 * @return
 */
public static AlertDialog showInformationDialog(String title, String message, Context context) {

    AlertDialog.Builder alt_bld = new AlertDialog.Builder(context);
    alt_bld.setMessage(message);
    alt_bld.setCancelable(false);
    alt_bld.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });

    AlertDialog alert = alt_bld.create();

    // Title for AlertDialog
    alert.setTitle(title);

    alert.show();
    return alert;
}

From source file:Main.java

private static AlertDialog buildErrorDialog(final Activity context, String title, String description,
        String buttonText) {//www. j a  va 2  s. c o m

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);
    builder.setMessage(description);
    builder.setCancelable(false);
    builder.setPositiveButton(buttonText, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, int which) {
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    dialog.dismiss();
                    context.finish();
                }
            });
        }
    });

    return builder.create();
}

From source file:Main.java

/**
 * showInformationDialog// w  w w  .  j  a v  a 2 s.  c o m
 *
 * @param title
 * @param message
 * @param context
 * @param positiveListener
 * @param showNegativeOption
 */
public static void showInformationDialog(String title, String message, Context context,
        DialogInterface.OnClickListener positiveListener, boolean showNegativeOption) {

    AlertDialog.Builder alt_bld = new AlertDialog.Builder(context);
    alt_bld.setMessage(message);
    alt_bld.setCancelable(false);
    alt_bld.setPositiveButton("Aceptar", positiveListener);
    if (showNegativeOption) {
        alt_bld.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
    }

    AlertDialog alert = alt_bld.create();

    // Title for AlertDialog
    alert.setTitle(title);

    alert.show();
}

From source file:Main.java

public static void showMessage(Context _context, String title, String message, int icon,
        DialogInterface.OnClickListener ackHandler) {
    AlertDialog.Builder builder = new AlertDialog.Builder(_context);
    builder.setTitle(title);/*from   w  ww  .j a v a2s.co  m*/
    builder.setMessage(Html.fromHtml(message));
    builder.setCancelable(false);
    builder.setPositiveButton("Acknowledged", ackHandler);
    builder.setIcon(icon);
    boolean show = true;
    if (_context instanceof Activity) {
        Activity activity = (Activity) _context;
        if (activity.isFinishing()) {
            show = false;
        }
    }
    if (show)
        builder.show();
}

From source file:Main.java

/**
 * This method shows an alert box with specified message
 * @param context/*  ww  w.j a  v  a 2 s.c om*/
 * @param message
 */
public static void displayAlert(final Context context, String message) {

    AlertDialog.Builder alert = new AlertDialog.Builder(context);

    alert.setTitle("Yumm! Alert:");
    alert.setMessage(message);
    alert.setCancelable(false);
    alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:Main.java

public static void ShowNoNetworkMessage(Context ctx) {

    AlertDialog.Builder alert = new AlertDialog.Builder(ctx);

    alert.setMessage("No network connection available.");
    //alert.setTitle("StormCloud");
    alert.setPositiveButton("OK", null);
    alert.setCancelable(true);
    alert.create().show();//from   w ww .  ja v a2 s.c o m
    //return alert;

}

From source file:Main.java

public static void showYesNoPrompt(Context _context, String title, String message,
        OnClickListener onYesListener, OnClickListener onNoListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(_context);
    builder.setTitle(title);/*from   w  w  w  .j  a  v a2 s  . c om*/
    builder.setIcon(android.R.drawable.ic_dialog_info); // lame icon
    builder.setMessage(message);
    builder.setCancelable(false);
    builder.setPositiveButton("Yes", onYesListener);
    builder.setNegativeButton("No", onNoListener);
    builder.show();
}