添加延迟进度对话框 [英] Add a delay to Progress Dialog

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

问题描述

我想打一个假的进度对话框出现2或3秒。它实际上并不会做任何事不是说检测等。我有code:

I want to make a dummy progress dialog appear for 2 or 3 seconds. It won't actually do anything other than say detecting. I have the code:

    ProgressDialog dialog = ProgressDialog.show(this, "", "Detecting...",
            true);
    dialog.show();

    dialog.dismiss();

但我唱戏,并解雇有对话框出现了几秒钟之间?谢谢!

But what do I put in between the show, and the dismissal to have the dialog appear for a few seconds? Thanks!

推荐答案

正确的方法 - 它不会阻止你的主线程,所以用户界面保持响应:

The correct way - it does not block your main thread, so UI stays responsive:

dialog.show();

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
        dialog.dismiss();
    }}, 3000);  // 3000 milliseconds

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

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