onPageFinished() 从未调用过(webview)!
我想在网络视图完全加载时显示一个祝酒词。但吐司从未出现,我不知道为什么......这是我的代码:
public class WebViewSignUp extends Activity{
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webviewsignup);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
((TextView)findViewById(R.id.home)).setOnClickListener(new OnClickListener(){
public void onClick(View v) {
finish();
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(mWebView, url);
Toast.makeText(getApplicationContext(), "Done!", Toast.LENGTH_SHORT).show();
}
});
mWebView.loadUrl("http://pabebbe.com/m/register");
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
}
}
I want to show a toast when the webview is totally loaded. But the toast never show up, i don't know why..here is my code:
public class WebViewSignUp extends Activity{
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webviewsignup);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
((TextView)findViewById(R.id.home)).setOnClickListener(new OnClickListener(){
public void onClick(View v) {
finish();
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(mWebView, url);
Toast.makeText(getApplicationContext(), "Done!", Toast.LENGTH_SHORT).show();
}
});
mWebView.loadUrl("http://pabebbe.com/m/register");
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对
setWebViewClient()
的第二次调用将覆盖第一次调用。仅创建一个
WebViewClient
实例,并在同一类中进行两个重写,并且仅调用一次setWebViewClient
。然后加载Webview:The second call to
setWebViewClient()
is overwriting the first.Create only a single instance of
WebViewClient
with both overrides in the same class, and callsetWebViewClient
only once. Then load the Webview:@mportuesisf 是 100% 正确的,还要注意在回调中您调用了错误的 webview 的 onPageFinished。如果您有多个使用客户端的 Web 视图,这可能是相关的。我会修复
:
@mportuesisf is 100% correct, also note in the callback you're calling the wrong webview's onPageFinished. This might be relevant if you have multiple webviews using the client. I would fix:
to