简体   繁体   中英

webview android with progress dialog

im trying to make an webview application for android with progress bar, i tried a lot of examples from here but none was working .. my problem is that on a frame page or a page with facebook likes or comment plugin the progressdialog never stoped .. here is my code.. please test it and tell me what is wrong.

private WebView webview;
private ProgressDialog progressDialog;
boolean loadingFinished = true;
boolean redirect = false;
int nr = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    webview = (WebView) findViewById(R.string.webview);

    final Activity activity = this;

    webview.getSettings().setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (!loadingFinished) {
                redirect = true;
             }

            loadingFinished = false;
            webview.loadUrl(url);

            return true;

        }

        public void onLoadResource(WebView view, String url) {
            if (progressDialog == null) {
                progressDialog = new ProgressDialog(activity);
                progressDialog.setTitle("PitziWorld");
                progressDialog.setMessage(progressDialog.toString());
                progressDialog.setCancelable(isFinishing());
                progressDialog.show();

            }
            loadingFinished = false;
        }
        public void onPageFinished(WebView view, String url) {

            if(!redirect){
                loadingFinished = true;
             }

             if(loadingFinished && !redirect){
                 if (progressDialog.isShowing() || progressDialog!=null) {
                     progressDialog.hide();
                     progressDialog = null;
                 }
             } else{
                redirect = false; 
             }




        }
    }); 
    webview.loadUrl("http://www.pitziworld.ro");

}
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        WebView webView = (WebView) findViewById(R.string.webview);
        //Verifica daca tasta apasata a fost back si daca exista istoric
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        // Daca nu a fost tasta back sau nu este istoric, returnam valoare buton

        `

this is what you are looking for!

         public void onPageStarted(WebView view, String url, Bitmap favicon) {
           mProgress.show();
       }

to load progress bar in every page this is it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM