【发布时间】:2011-03-25 14:31:10
【问题描述】:
嗨
在列表视图中,我有一个 webview,它应该从服务器加载图像文件,当没有图像存在时,我需要一个虚拟图像。我试过了
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。猜猜怎么做。
【问题讨论】:
-
我尝试使用 HttpClient 并在检查 HttpStatus 时,如果 HttpStatus 返回错误消息,我已经加载了 url,然后我限制加载 url,而是显示无图像 png。这种方法很麻烦吗,任何人都可以为此提出替代方案。
-
无法使用 WebView 完成,但是您可以使用基本的 HTTPClient 并检查响应代码。这是有关如何执行此操作的链接:stackoverflow.com/questions/2592843/…
标签: android webview webviewclient