android:显示进度对话框
我已经查看了 Android API 和 stackoverflow 上的其他帖子,但无法弄清楚这一点。
我的应用程序将文件下载到 SD 卡。我想在下载文件时弹出一个“正在加载...”对话框,然后在下载完成后让它消失。这是我使用 android API 想到的:
ProgressDialog pd = ProgressDialog.show(this,"","Loading. Please wait...",true);
//download file
pd.cancel();
但是该对话框实际上并未显示。当我调试它时,它声称它正在显示,但它显然不在屏幕上。
我能做些什么?
I have looked at the Android API and other posts here on stackoverflow, but have not been able to figure this out.
My app downloads files to the sd card. I would like to pop a "loading..." dialog while the file is downloading and then have it disappear when the download is finished. This is what i came up with using the android API:
ProgressDialog pd = ProgressDialog.show(this,"","Loading. Please wait...",true);
//download file
pd.cancel();
however the dialog doesn't actually show. when i debug it, it claims that it is showing, but it is obviously not on the screen.
what can i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将下载代码运行到单独的线程中。最简单的方法是使用 AsyncTask
另请参阅 这篇文章介绍如何使用它
You have to run the download code into a separated Thread. The easy way is to use AsyncTask
Look also this article on how to use it
我有一个有点类似的场景,更多的是在为游戏的一个阶段设置内容时的关卡加载暂停。我启动对话框,在传递上下文的线程中启动级别加载,并在线程末尾调用此方法:
我发现 runOnUiThread() 方法非常有用。
I have a somewhat similar scenario, more of a level loading pause while stuff is being setup for a phase of a game. I launch the dialog, start level loading in a thread which is passed the context and call this at the end of the thread:
I find the runOnUiThread() method extremely useful.