在我的android应用程序中,我想放置一个进度条,以便它向用户显示数据正在下载,并在数据加载后消失。
有什么办法可以实现这一点吗?
提前致谢:)
您可以通过AsyncTask类来实现它。
在这三个步骤中你必须遵循,
- 你必须启动ProgreesDialog
onPreExecute()
.
-
doInBackground()
控制下载进度。
-
onPostExcecute()
在第二步之后运行。您可以关闭进度对话框,启动新活动并完成闪屏。
更多信息,请检查文档。它有示例代码的解释。
CODE:
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();
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)