0

Can anyone help me when I add this ProgressDialog to my Webview app its work fine but when the page is loaded the progress dialog is not dismissed can anyone help me I am using this code in Fragment

public static ProgressDialog progressDialog;

     mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                    swipeRefreshLayout.setRefreshing(true);
                    progressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");

                    super.onPageStarted(view, url, favicon);

                }


                public void onPageFinished(WebView view, String url) {
                    swipeRefreshLayout.setRefreshing(false);
                    getActivity().setTitle(view.getTitle());
                    if(progressDialog!=null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    super.onPageFinished(view, url);

                }
            });

Edited code which is working for me now thanks to everyone who help me

public static ProgressDialog progressDialog;

//Under onCreate View
progressDialog = ProgressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");

mWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                swipeRefreshLayout.setRefreshing(true);
                super.onPageStarted(view, url, favicon);

            }


            public void onPageFinished(WebView view, String url) {
                swipeRefreshLayout.setRefreshing(false);
                getActivity().setTitle(view.getTitle());
                if(progressDialog!=null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog.hide();
                }
                super.onPageFinished(view, url);

            }
        });
Suman Dey
  • 57
  • 9
  • 2
    Possible duplicate of [How to add a progress/loading bar in WebView](https://stackoverflow.com/questions/47885592/how-to-add-a-progress-loading-bar-in-webview) – AskNilesh Mar 20 '18 at 04:52
  • @Suman Dey can you post ur full code?? – Jeeva Mar 20 '18 at 06:36
  • @Jeeva sorry I can not post the full line of code because the code is about 1000 line and have some serious codes which I can not share – Suman Dey Mar 20 '18 at 07:04

3 Answers3

0

Move below line out of onPageStarted() method, as it will be called for each underlying URL and it will keep on showing unless every css and js files are loaded

progressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
0

Make sure that if(progressDialog!=null && progressDialog.isShowing()) this condition returns true. Put a break point there and make sure they both are true.

try

 progressDialog.hide() 
user456
  • 262
  • 2
  • 9
0

Can you please try this code

progressDialog = ProgressDialog.show(getActivity(), "Loading...", "Please wait YouTube is Loading...");

Hope it helps

Jeeva
  • 1,791
  • 2
  • 23
  • 42