Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block UI for some seconds in android?

How can i block UI from all interactions for some seconds by user in Android?

I would like to know, how to do this with some delay timing like wait(5000);

like image 923
Adam Varhegyi Avatar asked Dec 04 '22 15:12

Adam Varhegyi


1 Answers

You can override dispatchTouchEvent and stop the call to super.dispatchTouchEvent(ev); Any touch event will have to go through this method before it is handled.

Set a boolean that you control and use it in the method to determine whether you wish to block control.

private boolean stopUserInteractions = false;

public boolean dispatchTouchEvent(MotionEvent ev) {
    if (stopUserInteractions) {
        return true;
    } else {
        return super.dispatchTouchEvent(ev);
    }
}
like image 86
cklab Avatar answered Dec 22 '22 05:12

cklab