当页面加载时,我会显示Progress Dialog,并在页面完成加载时将其关闭。之后,如果我向下滚动时加载图片,进度对话框将显示,但在图片加载后不会消失。我该如何解决这个问题?
这是我的代码,使用它,你就会明白我的意思。如果您能提供帮助,我将不胜感激。
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
// Declaring
WebView browser;
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initializing
browser = (WebView) findViewById(R.id.webView1);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setLoadWithOverviewMode(true);
browser.getSettings().setUseWideViewPort(true);
browser.getSettings().setBuiltInZoomControls(true);
// Loading
browser.loadUrl("http://www.tumblr.com/tagged/cool%20pictures");
// Progress Dialog
pd = ProgressDialog.show(MainActivity.this, "",
"Loading. Please wait...", true);
browser.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
view.loadUrl(url);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public void onLoadResource(WebView view, String url) {
try {
if (pd.isShowing() == false) {
pd = ProgressDialog.show(MainActivity.this, "",
"Loading. Please wait...", true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void onPageFinished(WebView view, String url) {
if (pd.isShowing()) {
pd.dismiss();
}
}
});
}
}