How to block UI for some seconds in android?

瘦欲@ 提交于 2019-12-04 13:12:47

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);
    }
}

Show Non-cancelable progress dialog and close it by code when you want.......

see example

http://www.helloandroid.com/tutorials/using-threads-and-progressdialog

You can pop up a modal, non-cancelable progress dialog that blocks the user from doing anything. However, you should never block the UI thread itself.

Use ProgressDialog in UI Block time. Set ProgressDialog cancel-able false. So user do not able to access UI.

Thanks.

As your Question is Short, you will get answer in that manner.

You can use Thread or AsyncTask for making some ProgressDialog being Visible for the User.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!