gpt4 book ai didi

android - 将进度微调器插入启动画面 android

转载 作者:太空狗 更新时间:2023-10-29 12:58:20 26 4
gpt4 key购买 nike

在我的 android 应用程序中,我想放置一个进度条,以便它向用户显示数据正在下载并在数据加载后消失。

有什么办法可以做到这一点。

提前致谢:)

最佳答案

可以通过AsyncTask类实现。

在这三个步骤中,您必须遵循,

  1. 您必须在 onPreExecute() 中启动 ProgreesDialog。
  2. doInBackground() 控制下载进度。
  3. onPostExcecute() 在第二步之后运行。在此基础上,您可以关闭进度对话框,启动新 Activity 并完成启动画面。

更多信息,查看Documentation .它有示例代码的解释。

代码:

  private class Task extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(
your_class.this);

// can use UI thread here
protected void onPreExecute() {
this.dialog.setMessage("Loading...");
this.dialog.setCancelable(false);
this.dialog.show();
}

@Override
protected Void doInBackground(Void... params) {
try {
// do downloading images code here
} catch (Exception e) {

}
return null;

}

protected void onPostExecute(Void result) {
//start the another activity and then close your current activity here.
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
}
}

关于android - 将进度微调器插入启动画面 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3740458/

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