简体   繁体   English

Android-WebView onReceivedError相反

[英]Android - WebView onReceivedError opposite

How do I know if there were no errors in loading a page in webview ? 我如何知道在webview中加载页面是否没有错误? Here is the code for the onReceivedError : 这是onReceivedError的代码:

    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            view.stopLoading();  // may not be needed
            switch (Locale.getDefault().toString()) {
                case "es_ES":
                    view.loadUrl("file:///android_asset/www/errorPage.forRestActivities.es_ES.HTML");
                    break;
                default:
                    view.loadUrl("file:///android_asset/www/errorPage.forRestActivities.en_US.HTML");
                    break;
            }
        }

    });

Setting a flag (isError) did the trick. 设置标志(isError)可以解决问题。 The flag is set to false when created, as an error is not what's supposes to happens. 创建该标志时,会将其设置为false,因为这不是应该发生的错误。 If it does happens then the flag is set to true. 如果确实发生,则将标志设置为true。 That flag is evaluated at onPageFinished . 该标志在onPageFinishedonPageFinished If it's true the buttons are not showed otherwise they're 如果为真,则不显示按钮,否则为

我会为此使用onPageFinished()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM