android:显示进度对话框

发布于 2024-09-05 07:59:19 字数 349 浏览 6 评论 0原文

我已经查看了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满意归宿 2024-09-12 07:59:19

您必须将下载代码运行到单独的线程中。最简单的方法是使用 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

絕版丫頭 2024-09-12 07:59:19

我有一个有点类似的场景,更多的是在为游戏的一个阶段设置内容时的关卡加载暂停。我启动对话框,在传递上下文的线程中启动级别加载,并在线程末尾调用此方法:

mContext.runOnUiThread(new Runnable(){
    public void run() {
        mContext.mProgressDialog.dismiss();
    }
});

我发现 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:

mContext.runOnUiThread(new Runnable(){
    public void run() {
        mContext.mProgressDialog.dismiss();
    }
});

I find the runOnUiThread() method extremely useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文