android:显示进度对话框 [英] android: showing a progress dialog

查看:167
本文介绍了android:显示进度对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在stackoverflow上查看了Android API和其他帖子,但无法弄清楚这一点。

I have looked at the Android API and other posts here on stackoverflow, but have not been able to figure this out.

我的应用程序将文件下载到SD卡。我想在文件下载时弹出一个加载...对话框,然后在下载完成后消失。这是我想到的使用android API:

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.

我可以做什么?

推荐答案

您必须将下载代码运行到单独的线程中。简单的方法是使用 AsyncTask

You have to run the download code into a separated Thread. The easy way is to use AsyncTask

另请参阅这篇文章< a>如何使用它

Look also this article on how to use it

这篇关于android:显示进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆