Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

I'm working on an android project which displays a progress dialog when the user downloads a file.

But when the user touches the screen, the progress dialog is dismissed without waiting the 100%. I already tried to use this:

 public boolean onTouchEvent(MotionEvent e) {         return true;     }  

But it's not working.

How can I avoid this?

UPDATE 1:

It seems that setCancelable(false) works fine. Thanks you very much for your answers but when the downloading long-lasting and the user decides to abandon it'll be impossible because I already deactivated the back keyCode:

@Override public boolean onKeyDown(int keyCode, KeyEvent event) {     if (keyCode == KeyEvent.KEYCODE_BACK) {         return true;     }     return super.onKeyDown(keyCode, event); } 

How can I figure this out?

like image 246
13KZ Avatar asked Mar 15 '13 12:03

13KZ


People also ask

What can I use instead of progress dialog?

ProgressBar is best alternative for ProgressDialog.

How do I stop progress bar?

You want to stop the progressDialog or change its UI not to be circular? You can set your progressbar's visibility to invisible or gone through progressbar. setVisibility(View. INVISIBLE); or progressBar.


1 Answers

Use dialog.setCancelable(false);

Example :

        ProgressDialog dialog = new ProgressDialog(WiFiFinderActivity.this);         dialog.setMessage("please wait...");         dialog.show();         dialog.setCancelable(false);         dialog.setCanceledOnTouchOutside(false); 
like image 55
Bhavesh Patadiya Avatar answered Sep 17 '22 23:09

Bhavesh Patadiya