【发布时间】:2010-09-20 19:06:35
【问题描述】:
在我的 android 应用程序中,我想放置一个进度条,以便它向用户显示数据正在下载并在数据加载后被关闭。
有没有什么方法可以实现。
提前致谢:)
【问题讨论】:
标签: android
在我的 android 应用程序中,我想放置一个进度条,以便它向用户显示数据正在下载并在数据加载后被关闭。
有没有什么方法可以实现。
提前致谢:)
【问题讨论】:
标签: android
你可以通过AsyncTask类来实现。
在这三个步骤中,您必须遵循,
onPreExecute() 中启动 ProgreesDialog。doInBackground() 控制下载进度。onPostExcecute() 在第二步之后运行。您可以关闭进度对话框,启动新活动并完成启动画面。更多信息,请查看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();
}
}
}
【讨论】:
@username: your comment。它为他们唤醒通知。它有助于获得快速响应。 ;)