Disable a whole activity from user action
If you need to disable event processing for a period of time (for instance, while you run an animation, show a waiting dialog), you can override the activity's dispatch functions.
To disable touch/clicks on any buttons, add these members/functions to your activity:
protected boolean enabled = true;
public void enable(boolean b) {
enabled = b;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return enabled ?
super.dispatchTouchEvent(ev) :
true;
}
Then just call enable(true/false)
when you need to disable and enable the activity's normal event handling.
Use AsyncTask with ProgressDialog bundled.
AsyncTask
Progress Dialog
another useful example:
http://www.screaming-penguin.com/node/7746
In order to block user touch events, use:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
To get touch events back, use:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
EDIT: If you want to add a feature of disable and greyed out display, you need to add in your xml layout file a linear layout that fills the parent. Set its background to #B0000000 and its visibilty to Gone. Than programicly set its visibility to Visible.