How to avoid dismissing my progress dialog when the user touches the screen?

You dont wanna use this Override function.. You just set

final Dialog dialog=new Dialog(dialogactivity.this);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);

Try myDialog.setCancelable(false);. I'm not sure if a Progress Dialog has that method same as a AertDialog, but it may be worth a try.

Edit (to add for your update): Try using the following:

myDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            //do your canceling stuff here
        }
    });

Also are you doing this in an AlertDialog or are you using AlertDialog.Builder?

IF you are useing AlertDialog.Builder you should use the following:

AlertDialog myProgressDialog = myDialog.create();
myProgressDialog.show();

Then you should be able to use myProgressDialog.dismiss(); in your NegativeButton onClick.


You can use this line

dialog.setCanceledOnTouchOutside(false);

or

dialog.setCancelable(false);

as per your reqirement


Use dialog.setCancelable(false);

Example :

        ProgressDialog dialog = new ProgressDialog(WiFiFinderActivity.this);
        dialog.setMessage("please wait...");
        dialog.show();
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);

Tags:

Java

Android