Tuesday, May 10, 2011

Loader for WebView : Android

To set Loader for webview,Set the webviewclient and override OnpageStarted,onPageFinished and onReceivedError.

ProgressDialog _dialog ; //  Global Variable

WebView webView = (WebView)findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient(){

   
   @Override
   public void onPageStarted(WebView view, String url, Bitmap favicon) {
        _dialog =ProgressDialog.show(CurrentActivity.this, "", "Please wait...");
    super.onPageStarted(view, url, favicon);
   }  //  end  OnPageStarted

   @Override
   public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    _dialog.dismiss();
   }  //  end OnPageFinished()
   
   @Override
   public void onReceivedError(WebView view, int errorCode,
     String description, String failingUrl) {
    super.onReceivedError(view, errorCode, description, failingUrl);
    try{
     _dialog.dismiss();
    }catch (Exception e) {
     // TODO: handle exception
    }
   }  //  end onReceivedError()
   
  }); // end WebViewclient

When onPageStarted is called ,start the dialog and finish in onPageFinished , onRecievedError() methods.

2 comments:

  1. explication not enough

    I have an issue with the Bitmap

    ReplyDelete
  2. I'm unable to get what you are asking.Do u mean bitmap in OnpageStarted()?

    ReplyDelete