Viresh
Viresh

Reputation: 323

How can I avoid dismissing my AlertDialog.Builder dialog when the user touch the screen?

I'm working on an android project which a custom alert dialog, it has one textview and Button.

edt.setText("Enter Comment");
    AlertDialog.Builder builder = new AlertDialog.Builder(
                    CameraActivity.this);
            builder.setTitle("Enter your Comment");
            lnrt.addView(edt);
            builder.setView(lnrt);

            builder.setNegativeButton("SUBMIT", new OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    edText = edt.getText().toString();
                    new upDb(2).execute();
                }
            });

            builder.create();
            builder.show();

when i touch out side dialog its getting hide, how to avoid this? please help me.

Upvotes: 16

Views: 9610

Answers (3)

indrajeet
indrajeet

Reputation: 351

Try this one...

AlertDialog.Builder alert = new AlertDialog.Builder(this);
...
...
alert.setCancelable(false);
final AlertDialog dialog = alert.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();

Upvotes: 4

matejs
matejs

Reputation: 3536

This will prevent your dialog from closing when user touches area outside dialog:

dialog.setCanceledOnTouchOutside(false);

Upvotes: 1

pshegger
pshegger

Reputation: 2596

Try

builder.setCancelable(false);

before you show the window, it does exactly what you want.

Upvotes: 32

Related Questions