Android: Detect when a WebView has finished loading

0 Comments

To know when a WebView has finished loading, you can set a WebViewClient() handler and override the onPageFinished() method.

01.ProgressDialog progressDialog = new ProgressDialog(ResultActivity.this);
02.progressDialog.setMessage("Loading ...");
03. 
04.progressDialog.setCancelable(false);
05.progressDialog.show();
06. 
07.WebView wv = new WebView(this);
08. 
09.wv.setWebViewClient(new WebViewClient() {
10.  @Override
11.  public void onPageFinished(WebView view, String url) {
12.    super.onPageFinished(view, url);
13.    progressDialog.hide();
14.  }
15.});
16. 
17.wv.loadUrl(some_url);

This example shows a "loading dialog" while the webview loads in the background. It'll go away once the page has fully loaded.

1246086511568

Just like when the Jedi warriors have finished defeating enemies, at the end of the battle they force push a fat dude off his chair.

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog