boolean errorOccurred = false; // Global variable
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
hideError();
showProgress();
Toast.makeText(Test.this, "start loading", Toast.LENGTH_SHORT).show();
errorOccurred=false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (!errorOccurred) {
hideError();
}
hideProgress();
Toast.makeText(Test.this, "Web view was loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
errorOccurred = true;
hideProgress();
showError();
Toast.makeText(Test.this, "Could not load your page", Toast.LENGTH_SHORT).show();
super.onReceivedError(view, errorCode, description, failingUrl);
Toast.makeText(Test.this, "error", Toast.LENGTH_SHORT).show();
}
});