【问题标题】:I have button when I click on that button I want to show progress dialog only for 2 seconds, how to dismiss progress dialog after 2 seconds单击该按钮时我有按钮我只想显示进度对话框 2 秒,如何在 2 秒后关闭进度对话框
【发布时间】:2018-03-19 19:07:19
【问题描述】:

当我点击那个按钮时我有按钮我只想显示 2 秒的进度对话框,如何在 2 秒后关闭进度对话框

@Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressDialog = new ProgressDialog(ActivityTalentHunt.this);
            progressDialog.setMessage("Page is loading...");
            progressDialog.show();
            Thread mythread=new Thread(){

                @Override
                public void run() {
                    try {
                        sleep(2000);
                    }catch (Exception e) {
                        e.printStackTrace();
                    }finally {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                progressDialog.dismiss();

                            }
                        });
                    }
                }
            };
            mythread.start();
        }

【问题讨论】:

  • 你的代码不工作或者你的问题是什么?
  • 问题已解决。

标签: android


【解决方案1】:

您可以使用Handler

你需要导入import android.os.Handler;

    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
            final ProgressDialog progressDialog = new ProgressDialog(ActivityTalentHunt.this);
            progressDialog.setMessage("Page is loading...");
            progressDialog.show();

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    progressDialog.dismiss();
                }
            },2000);

        }
    });

【讨论】:

  • @AbdulBasitRishi 很乐意帮助你
  • 知道了。再次感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-12
  • 1970-01-01
  • 1970-01-01
  • 2017-09-02
  • 2013-04-06
  • 1970-01-01
相关资源
最近更新 更多