hi
在列表视图中,我有一个网络视图,它应该从服务器加载图像文件,当没有图像时,我需要一个虚拟图像。我尝试过
holder.image.setWebViewClient(new WebViewClient()
{
@Override
public void onReceivedError( WebView view, int errorCode, String description, String failingUrl)
{
System.out.println("description error" + description);
view.setVisibility( View.GONE );
}
@Override
public void onPageFinished(WebView view, String url) {
view.setVisibility( View.VISIBLE );
}
});
我在 FrameLayout 中有一个带有虚拟图像的 webview,加载每个图像 url 后都会调用 onPageFinished 侦听器,但不会为产生 404 错误的 url 调用 onReceivedError。任何猜测如何做到这一点。
我必须重写 WebViewClient.onReceivedHttpError() 而不是 WebViewClient.onReceivedError()。
@Override
public void onReceivedHttpError(final WebView view, final WebResourceRequest request, WebResourceResponse errorResponse) {
final int statusCode;
// SDK < 21 does not provide statusCode
if (Build.VERSION.SDK_INT < 21) {
statusCode = STATUS_CODE_UNKNOWN;
} else {
statusCode = errorResponse.getStatusCode();
}
Log().d(LOG_TAG, "[onReceivedHttpError]" + statusCode);
}
来自 WebClient 文档:
/**
* Notify the host application that an HTTP error has been received from the server while
* loading a resource. HTTP errors have status codes >= 400. This callback will be called
* for any resource (iframe, image, etc), not just for the main page. Thus, it is recommended to
* perform minimum required work in this callback. Note that the content of the server
* response may not be provided within the <b>errorResponse</b> parameter.
* @param view The WebView that is initiating the callback.
* @param request The originating request.
* @param errorResponse Information about the error occured.
*/
public void onReceivedHttpError(
WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)