Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Show loading when load page on WebView

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 232
    Comment on it

    Here I am writing code to load url on WebView.
    We need to create WebView client where we get the event of page finished.


    Then simply showing ProgressDialog and dismiss it on onPageFinished().

        WebView myWebView ; 
    myWebView = (WebView)findViewbyId(R.id.my_web_view);
    
        myWebView.setWebViewClient(new WebViewClient() {       
            ProgressDialog  mProgressDialog; 
    
                public boolean shouldOverrideUrlLoading(WebView view, String url) {               
                view.loadUrl(url); 
                return true; 
            } 
    
            //Show loader on url load 
            public void onLoadResource (WebView view, String url) { 
                if (mProgressDialog == null) { 
                              mProgressDialog = new ProgressDialog(MyActivity.this); 
                    mProgressDialog.setMessage("Loading..."); 
                    mProgressDialog.show(); 
                } 
            } 
            public void onPageFinished(WebView view, String url) { 
    
    try{ 
                    if (mProgressDialog.isShowing()) { 
                        mProgressDialog.dismiss(); 
                        mProgressDialog = null; 
                    } 
                    }catch(Exception e){ 
                        e.printStackTrace(); 
                    } 
                } 
    
        });  
    
         // Javascript inabled on webview   
        webView.getSettings().setJavaScriptEnabled(true);  
    
    
        //Load url in webview 
        webView.loadUrl(url); 
    
    
    } 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: