Abdul Basit Rishi
Abdul Basit Rishi

Reputation: 2425

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

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

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

Upvotes: 0

Views: 48

Answers (1)

AskNilesh
AskNilesh

Reputation: 69709

You can use Handler

You need to import 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);

        }
    });

Upvotes: 1

Related Questions