Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AlertDialog setOnCanceledOnTouchOutside

I create AlertDialog, I set setOnCanceledOnTouchOutside and setCancelable params, but then I click outside dialog it hides. Maybe someone can help me?

dialog = new AlertDialog.Builder(getContext()).setView(table).setTitle(R.string.order_start_title)
.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int whichButton) {
        onOrderStartCancel(context);
    }
}).setPositiveButton(R.string.dialog_start_order, new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int whichButton) {
        onOrderStart(context, goodsTypeId, goodType);
    }
}).create();
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
dialog.show();
like image 571
user1582087 Avatar asked Mar 02 '26 22:03

user1582087


1 Answers

If you dont want to allow user to cancel dialog then

use

dialog.setCancelable(false);
                     ^^^^^

instead of

dialog.setCancelable(true);

also remove this dialog.setCanceledOnTouchOutside(true); <--- if not needed.

like image 99
MAC Avatar answered Mar 04 '26 12:03

MAC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!