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 showConfirmDialog(Context context, String title, String message, String strPositiveButton,
        String strNegativeButton, DialogInterface.OnClickListener positiveOnclick,
        DialogInterface.OnClickListener negativeOnClick, boolean cancelAble,
        DialogInterface.OnCancelListener cancelListener) {
    if (context == null) {
        return;/*from   w ww. ja  v  a 2 s.  c  om*/
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    if (title != null) {
        builder.setTitle(title);
    }

    builder.setMessage(message);
    if (TextUtils.isEmpty(strPositiveButton)) {
        builder.setPositiveButton(strPositiveButton, positiveOnclick);
    } else {
        builder.setPositiveButton(strPositiveButton, positiveOnclick);
    }
    if (!TextUtils.isEmpty(strNegativeButton)) {
        builder.setNegativeButton(strNegativeButton, negativeOnClick);
    }
    builder.setCancelable(cancelAble);
    builder.setOnCancelListener(cancelListener);
    builder.create().show();
}

From source file:com.todotxt.todotxttouch.util.Util.java

public static void showDialog(Context cxt, int titleid, String msg) {
    AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
    builder.setTitle(titleid);//from  w  w w. j av  a  2s.  co m
    builder.setMessage(msg);
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setCancelable(true);
    builder.show();
}

From source file:com.todotxt.todotxttouch.util.Util.java

public static void showDialog(Context cxt, int titleid, int msgid) {
    AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
    builder.setTitle(titleid);//from ww w  . j ava  2s  .  c om
    builder.setMessage(msgid);
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setCancelable(true);
    builder.show();
}

From source file:com.doplgangr.secrecy.utils.Util.java

public static void alert(final Context context, final String title, final String message,
        final DialogInterface.OnClickListener positive, final DialogInterface.OnClickListener negative) {
    new Handler(Looper.getMainLooper()).post(new Runnable() {

        @Override/*from ww w .j  a  v a2s  . co  m*/
        public void run() {
            AlertDialog.Builder a = new AlertDialog.Builder(context);
            if (title != null)
                a.setTitle(title);
            if (message != null)
                a.setMessage(message);
            if (positive != null)
                a.setPositiveButton("OK", positive);
            if (negative != null)
                a.setNegativeButton("CANCEL", negative);
            a.setCancelable(false);
            a.show();
        }

    });
}

From source file:com.evozi.droidsniff.helper.DialogHelper.java

public static void showDisclaimer(final Activity context) {

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

    builder.setMessage(R.string.license);
    builder.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();/*from w ww.  j a  v a 2s  .c o m*/
        }
    }).setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            context.finish();
        }
    });

    builder.setCancelable(false);
    builder.show();
}

From source file:com.doplgangr.secrecy.Util.java

public static void alert(final Context context, final String title, final String message,
        final DialogInterface.OnClickListener positive, final DialogInterface.OnClickListener negative) {
    new Handler(Looper.getMainLooper()).post(new Runnable() {

        @Override/*w  ww .j  a  va2s.c om*/
        public void run() {
            AlertDialog.Builder a = new AlertDialog.Builder(context);
            if (title != null)
                a.setTitle(title);
            if (message != null)
                a.setMessage(message);
            if (positive != null)
                a.setPositiveButton(context.getString(R.string.OK), positive);
            if (negative != null)
                a.setNegativeButton(context.getString(R.string.CANCEL), negative);
            a.setCancelable(false);
            a.show();
        }

    });
}

From source file:com.ibuildapp.romanblack.CataloguePlugin.utils.Utils.java

/**
 * Show alert dialog with passed params//from  w w  w  . j  a  v  a2 s  . c  o  m
 *
 * @param context                     context
 * @param title                       title of dialog
 * @param message                     message of dialog
 * @param positiveButtonText          text of positive button (OK, for example)
 * @param negativeButtonText          text of positive button (CANCEL, for example)
 * @param onDialogButtonClickListener listener of clicks dialog's buttons
 */
public static void showDialog(final Context context, final int title, final String message,
        final int positiveButtonText, final int negativeButtonText,
        final OnDialogButtonClickListener onDialogButtonClickListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message);
    builder.setTitle(title);
    builder.setCancelable(false);
    builder.setPositiveButton(positiveButtonText,
            onDialogButtonClickListener != null ? new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onDialogButtonClickListener.onPositiveClick(dialog);
                }
            } : null);
    builder.setNegativeButton(negativeButtonText,
            onDialogButtonClickListener != null ? new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onDialogButtonClickListener.onNegativeClick(dialog);
                }
            } : null);
    builder.create().show();
}

From source file:Main.java

public static void showServiceError(Context context, int id) {

    String msg = "";

    if (id == -1) {

        msg = "could not complete query. Missing parameter";

    } else if (id == 0) {

        msg = "no data found";

    } else {/*from   w  ww. java  2  s. c o m*/
        msg = "something bad happend";
    }

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

    // Setting Dialog Title
    alert.setTitle("Alarm");
    // Setting Dialog Message
    alert.setMessage(msg);

    alert.setPositiveButton("Try Again", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // chkVersionData();
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
        }
    });

    alert.setCancelable(false);
    alert.show();

}

From source file:com.todotxt.todotxttouch.util.Util.java

public static void showConfirmationDialog(Context cxt, int msgid, OnClickListener oklistener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
    // builder.setTitle(cxt.getPackageName());
    builder.setMessage(msgid);//www  .  j  a  v a 2s .co  m
    builder.setPositiveButton(android.R.string.ok, oklistener);
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setCancelable(true);
    builder.show();
}

From source file:com.todotxt.todotxttouch.util.Util.java

public static void showConfirmationDialog(Context cxt, int msgid, OnClickListener oklistener, int titleid) {
    AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
    // builder.setTitle(cxt.getPackageName());
    builder.setTitle(titleid);//  w w w  .  j  ava 2 s  .  co  m
    builder.setMessage(msgid);
    builder.setPositiveButton(android.R.string.ok, oklistener);
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setCancelable(true);
    builder.show();
}