I have Webview application that uses progress bar dialog. It works fine but the issue is that the URL i’m showing is a basic form where a user has to enter some information.
The progress bar loads every time a user hits a button to do some action. the progress bar in this app and the loading message in the webpage overlap each other. you could see both of them showing up in the same time at the second and third page.
How do I get the progress bar in my app to function only one time, and that would be when the first page loads. Here’s my activity:
public class Webform extends Activity {
private WebView webview;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webform);
webview = (WebView) findViewById(R.id.webview);
final Activity activity = this;
webview.loadUrl("http://www.ccsuhealth.mobi");
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource (WebView view, String url) {
if (progressDialog == null) {
progressDialog = new ProgressDialog(activity);
progressDialog.setMessage("Loading... ");
progressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
progressDialog.cancel();
}
}
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(Webform.this, "Your Internet Connection May not be active Or " + description , Toast.LENGTH_LONG).show();
}
});
}
If I understand you correctly, you want to show the progress bar only on the first page (the login page), but not on the subsequent pages. Here is how to do it:
Implement the onPageStated event and activate the progress bar in there — but only if the URL matches your desired login page URL.
http://developer.android.com/reference/android/webkit/WebViewClient.html#onPageStarted(android.webkit.WebView, java.lang.String, android.graphics.Bitmap)
Implement the WebChromeClient.onProgressChange event. Set the progress bar progress in onProgressChange — but only if the progress bar is visible.
http://developer.android.com/reference/android/webkit/WebChromeClient.html#onProgressChanged(android.webkit.WebView, int)
Implement the onPageFinished event and hide the progress bar in there.
http://developer.android.com/reference/android/webkit/WebViewClient.html#onPageFinished(android.webkit.WebView, java.lang.String)