Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to disable controls during progress bar is active

I show my infinte progress bar in the action bar "as usual":

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
...
setProgressBarIndeterminateVisibility(true);
...
setProgressBarIndeterminateVisibility(false);

and the real work is done in a background thread (AsyncTask)

The problem: all controls on the UI are enabled, so the user can continue to modify the underlying data before the long lasting process is finished.

Simply disabling all controls is not possible because when disabling an EditText, also the keyboard is closed automatically by Android.

Any ideas how to prevent user input during the background work?

Thanks,

Chris

like image 700
cor Avatar asked Sep 06 '12 13:09

cor


People also ask

What are the different types of progress bars?

There are 2 types of progress bars: determinate and indeterminate. The former is used when the amount of information that needs to be loaded is detectable. The latter is used when the system is unsure how much needs to be loaded or how long it will take.

What is indeterminate progress bar android?

Indeterminate Progress Bar is a user interface that shows the progress of an operation on the screen until the task completes. There are two modes in which you can show the progress of an operation on the screen. In this Android Indeterminate Progress Bar example, we will discuss in detail.

Is a user interface Control which is used to Indicate the progress of an operation?

Progress bar is a user interface control that shows the progress of any operation.


2 Answers

What you can do is to bring up an invisible dialog and prevent it from being cancellable. It will show whatever is underneath it but disable all underlying user interaction. Then once you are done with your business you simply dismiss it and go on with your life:

Dialog mOverlayDialog = new Dialog(mContext, android.R.style.Theme_Panel); //display an invisible overlay dialog to prevent user interaction and pressing back
mOverlayDialog.setCancelable(false);
mOverlayDialog.show();  
like image 102
Chris Avatar answered Sep 21 '22 13:09

Chris


try putting progressDialog.setcancelable(false);

like image 43
Aditya Nikhade Avatar answered Sep 20 '22 13:09

Aditya Nikhade