Progress dialog in Android

半腔热情 提交于 2019-12-23 04:24:31

问题


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..


回答1:


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




回答2:


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);
}


来源:https://stackoverflow.com/questions/5431429/progress-dialog-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!