How do i make my progress dialog dismiss after webview is loaded?

后端 未结 6 1466
一向
一向 2020-12-10 17:22

What do I need to my code to make the dialog dismiss() after the webview is loaded?

public void onCreate(Bundle savedInstanceState) { 
                  


        
6条回答
  •  眼角桃花
    2020-12-10 18:19

    How are you accessing pd in onPageFinshed()? (And are you sure it's actually called when the page loads?)

    In your onCreate(), try passing pd to your homeClient so that homeClient can take care of dismissing the dialog.

    Your homeClient should look like this:

    private class homeClient extends WebViewClient {
    
        private ProgressDialog pd;
    
        public homeClient(ProgressDialog pd) {
            this.pd = pd;
        }
    
        @Override 
        public boolean shouldOverrideUrlLoading(WebView view, String url) {           
            view.loadUrl(url); 
            return true; 
        } 
    
        @Override
        public void onPageFinished (WebView view, String url) {
            if (pd.isShowing()) {
                pd.dismiss();
            }
        }
    }
    

    In your onCreate():

    ProgressDialog pd = ProgressDialog.show(Fbook.this, "", 
                    "Loading. Please wait...", true);
    webview.setWebViewClient(new homeClient(pd));
    

提交回复
热议问题