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