android - 异步任务上的模态 HUD

标签 android

我正在 Android 中做一些事情。将有一个菜单,访问时会从服务器(500 多个)请求相当大的用户列表,大约需要 5 秒。在此期间,应用程序卡住。我如何着手显示一个进度 HUD(如 MBProgressHud),用户可以在其中意识到正在发生的事情并且在它完成之前无法触摸它。

MBProgressHud:

HUD Example

最佳答案

使用异步任务:

public class MyAsyncTask extends AsyncTask<Void, Void, Result>{

                        private Activity activity;
                        private ProgressDialog progressDialog;

            public MyAsyncTask(Activity activity) {
                            super();
                this.activity = activity;
            }

            @Override
            protected void onPreExecute() {
            super.onPreExecute();
                progressDialog = ProgressDialog.show(activity, "Loading", "Loading", true);
            }

            @Override
            protected Result doInBackground(Void... v) {
            //do your stuff here
            return null;

            }

            @Override
            protected void onPostExecute(Result result) {
                progressDialog.dismiss();
                Toast.makeText(activity.getApplicationContext(), "Finished.", 
                        Toast.LENGTH_LONG).show();
            }


}

从 Activity 中调用它:

MyAsyncTask task = new AsyncTask(myActivity.this);
task.execute();

关于android - 异步任务上的模态 HUD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11989446/

相关文章:

android - 具有 3 个 TextView 的水平 LinearLayout,其中第 2 个必须居中

android - 如何在低于 11 的 Api 中设置 View alpha?

android - 获取 Android 手机联系人的跨设备唯一 ID

java - 如何使用蓝牙 getInputStream 和 getOutputStream 的 pyjnius 读写参数?

java - 每次按下按钮时都会创建一个新的计时器实例

android - 如何使用 Android MediaPlayer 使 AAC 可通过 http 流进行搜索?

java - SnapHelper 项目位置

java - 将新 fragment 添加到 FrameLayout 会产生 IllegalStateException

android - 使用 facebook graph api 获取 friend 生日 v2.0

Android:setBackgroundTintList 在支持 fab 上工作,setSupportBackgroundTintList 导致 npe