gpt4 book ai didi

android - 异步任务上的模态 HUD

转载 作者:太空宇宙 更新时间:2023-11-03 12:39:05 25 4
gpt4 key购买 nike

我正在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com