I have a web view and i have this code (P.S i am a beginer in programming)
private WebChromeClient getChromeClient() { return new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { progressDialog.show(); if (newProgress ==100){ progressDialog.dismiss(); } super.onProgressChanged(view, newProgress); mWebView.setVisibility(View.GONE); } }; }
I already have webview client and webchrome client, you can see and download my code files here (cloud.mail.ru/public/2hHz/25DMkxh3U)
class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return super.shouldOverrideUrlLoading(view, url); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { mWebView.setVisibility(View.GONE); super.onPageStarted(view, url, favicon); } @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); } @Override public void onPageFinished(WebView view, String url) { if (mbErrorOccured == false && mbReloadPressed) { hideErrorLayout(); mbReloadPressed = false; } super.onPageFinished(view, url); mWebView.setVisibility(View.VISIBLE); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { mbErrorOccured = true; showErrorLayout(); super.onReceivedError(view, errorCode, description, failingUrl); } }
At the top you can see my code in Main activity.
Advertisement
Answer
You can check how to find if the webview loaded completely at this link : here
Once you start loading the webview, you can start a handler and check if the page is loaded completely, or you can reload the webpage.
final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { // check if the webview is loaded completely after 30 seconds here //if the page is not loaded then call the below line to reload // mWebview.loadUrl("http://www.google.com"); } }, 30000);