Android Webview 加载对话框没有被关闭
我正在使用以下代码
class CustomWebViewClient extends WebViewClient {
Context context;
ProgressDialog pd = null;
public CustomWebViewClient (Context c){
context = c;
}
public void onPageFinished(WebView view, String url){
pd.dismiss();
}
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
pd = ProgressDialog.show(context, "", "pageload. Please wait...", true);
view.loadUrl(url);
return true;
}
}
当我单击 WebView 中的链接时,会出现对话框并且页面开始加载,但是当页面加载完成时,对话框仍然在屏幕上。显然代码很简单,但我无法弄清楚。另外,我想我应该补充一点,所单击的链接有一些重定向,但我不确定这是否与此处的原因有关。
我怎样才能正确地做到这一点?
I am using the following code
class CustomWebViewClient extends WebViewClient {
Context context;
ProgressDialog pd = null;
public CustomWebViewClient (Context c){
context = c;
}
public void onPageFinished(WebView view, String url){
pd.dismiss();
}
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
pd = ProgressDialog.show(context, "", "pageload. Please wait...", true);
view.loadUrl(url);
return true;
}
}
When I click a link in the WebView, the dialog appears and the page begins to load, however when the page is finished loading, the dialog is still on the screen. Obviously the code is simple enough, but I cant figure this out. Also, I guess I should add that the links being clicked have a few redirects, but I am not sure if that is related to the cause here.
How can I do this right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您错过了
@Override
注释。这是正确的代码:
此代码有效,但初始加载时不会出现进度对话框。如果需要,请将此代码添加到类的构造函数中:
You missed
@Override
annotation.Here is right code:
This code works, but progress dialog does't appears on initial loading. If you need it, add this code to the class' constructor:
这确实有效,
你拼写 Finished 错了,你写了“onPageFinshed”
This does work,
you spelled Finished wrong, you wrote "onPageFinshed"
史蒂文& Sander,尝试在处理程序中关闭进度对话框,
如下所示:
然后在 onPageFinished 中调用处理程序:
&你完成了!
Steven & Sander, try dismissing the progress dialog in a Handler
Something like this:
Then call your handler in onPageFinished:
& you are done!