progressdialog not dismiss after page loading, here what i am missing
final ProgressDialog progressDialog = new ProgressDialog(Webview.this );
WebView webview= (WebView) findViewById(R.id.webViewID);
webview.setWebViewClient(new WebViewClient());
//webview.loadData(content, "text/html", "UTF-8");
webview.loadUrl("http://hop.betfanplus.com/10000/0/mega4");
webview.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
// progressDialog.show();
ProgressDialog
.show(Webview.this,
"ProgressDialog Title",
"ProgressDialog Body");
if (progress == 100) {
progressDialog.dismiss();
}
}
});
any help is appreciated.
You should still use onPageStarted and onPageFinished.
From my experience, using progress percentage will reach 100 even if the webpage fails to load, so that won't work.
boolean loadingFinished = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressDialog progressDialog = new ProgressDialog(Webview.this );
progressDialog.setMessage("ProgressDialog Body");
progressDialog.show();
WebView webview= (WebView) findViewById(R.id.webViewID);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), description, Toast.LENGTH_SHORT).show();
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loadingFinished = false;
}
public void onPageFinished(WebView view, String url) {
loadingFinished = true;
progressDialog.cancel();
}
});
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("http://hop.betfanplus.com/10000/0/mega4");
}