0

I'm trying to create a simple app for android with progress bar. Everything works fine. But, here two issues

1) When the application is launched i can see progress loading twice.

2) How can i disable the progress bar after the initial page is finished loading. I dont want to show the progressbar on each click..

Here is my code

package com.mycom.jquery;
import android.app.Activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class HelloWebView extends Activity {

WebView webview;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
            Window.PROGRESS_VISIBILITY_ON);

    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

    });
    final Activity activity = this;

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMessage("Loading...Jquery.com");
    progressDialog.setCancelable(true);

    webview.loadUrl("http://www.jquery.com");

    // WebChromeClient give progress etc info
    webview.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress) {
            progressDialog.show();
            progressDialog.setProgress(0);
            activity.setProgress(progress * 1000);

            progressDialog.incrementProgressBy(progress);

            if (progress == 100 && progressDialog.isShowing())
                progressDialog.dismiss();
        }
    });

}

}
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
suraj jain
  • 1,012
  • 14
  • 26

3 Answers3

2

Try calling

progressDialog.show();

outside of

onProgressChanged(WebView view, int progress)
5hssba
  • 8,079
  • 2
  • 33
  • 35
1

Set a flag when progress becomes 100, and then if that flag is true immediately return in your onProgressChanged implementation.

sastraxi
  • 1,330
  • 11
  • 21
0

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

try removing this. from your code.

Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
Prashant Mishra
  • 627
  • 5
  • 18