android:显示进度对话框

android:显示进度对话框

问题描述:

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

I have looked at the Android API and other posts here on *, 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

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

Look also this article on how to use it