Android 中的进度对话框

发布于 2024-10-26 03:05:24 字数 122 浏览 5 评论 0原文

我完全了解如何在我的应用程序中显示进度对话框。我只是想知道我们是否可以为此进度对话框设置“超时”间隔。 [我的意思是有没有相关的 API]

我总是可以为此运行一个线程,但我认为如果已经有一个内置的 API 会更好。

I am fully aware on how to display progress dialogues in my application. I just want to know if there is anyway that we can set a "timeout" interval for this progress dialog. [I mean is there any API for this]

I can always run a thread for this, but thought it would be better if there was an inbuilt API already..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

匿名的好友 2024-11-02 03:05:24

没有内置的 api。只需使用 AsyncTask 或线程,您已经提到过。

There is no built-in api. Just use AsyncTask or thread, how you have already mentioned.

冷月断魂刀 2024-11-02 03:05:24

您也可以使用处理程序(将延迟消息发送到处理程序,处理程序将关闭对话框)。我不知道有什么方法可以告诉对话框在给定时间后自行关闭。

private ProgressDialog dialog;
private Handler closeHandler = new Handler() {
  public void handleMessage(Message msg) {
    if (dialog!=null) dialog.dismiss();
  }
};


public void openDialog() {
  // Open the dialog

  // Close it after 2 seconds
  closeHandler.sendEmptyMessageDelayed(0, 2000);
}

You can use a Handler as well (post a delayed message to the handler and the handler will close the dialog). I don't know any way to tell the dialog to close itself after a given time.

private ProgressDialog dialog;
private Handler closeHandler = new Handler() {
  public void handleMessage(Message msg) {
    if (dialog!=null) dialog.dismiss();
  }
};


public void openDialog() {
  // Open the dialog

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