如何再次在webview中加载failingUrl?
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.webView); //webview in activity_main.xml
[....] // some other codes
web.loadUrl("http://my-example-site.com");
[....] // some other codes
}
// if no network, then show error.xml with a reload button;
@Override
public void onReceivedError(final WebView view, int errorCode, String description, final String failingUrl){
setContentView(R.layout.error);
button = (Button) findViewById(R.id.button1); // Reload Button in error.xml
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
web.loadUrl(failingUrl); //this one is not working...
}
});
}
我想再次加载failingUrl ..
答案 0 :(得分:0)
试试此代码
@Override
public void onReceivedError(final WebView view, int errorCode, String description, final String failingUrl)
{
setContentView(R.layout.error);
button = (Button) findViewById(R.id.button1); // Reload Button in error.xml
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
web.reload();
}
});
}
您必须在初始化webview之前添加此声明
web.setWebViewClient(new WebViewClient());