Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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.

like image 413
Viresh Avatar asked Nov 22 '13 09:11

Viresh


3 Answers

Try

builder.setCancelable(false);

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

like image 168
pshegger Avatar answered Nov 03 '22 10:11

pshegger


Try this one...

AlertDialog.Builder alert = new AlertDialog.Builder(this);
...
...
alert.setCancelable(false);
final AlertDialog dialog = alert.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
like image 20
indrajeet Avatar answered Nov 03 '22 11:11

indrajeet


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

dialog.setCanceledOnTouchOutside(false);
like image 1
hendrix Avatar answered Nov 03 '22 11:11

hendrix