0

当 webview 完成加载网页时,我想关闭 ProgressDialog,它对我不起作用。这是我的代码:

    package com.mcc.ghurbo;


import java.security.PublicKey;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class GhurboActivity extends Activity {
    /** Called when the activity is first created. */ 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);



        final WebView mywebview=(WebView)findViewById(R.id.webview);
        mywebview.getSettings().setJavaScriptEnabled(true);
        mywebview.setWebViewClient(new WebViewClient());
        final ProgressDialog p=new ProgressDialog(GhurboActivity.this);
        p.show(GhurboActivity.this, "", "Loading...");





        Thread loading=new Thread(){
                public void run(){
                        try {

                              mywebview.loadUrl("http://www.google.com");

                          } 
                        //end of try
                        catch(Exception e ){
                             e.printStackTrace();
                       }// end of catch
                        finally{
                            p.dismiss();
                        }//end of finally
              }//end of run
     };//end of thread
     loading.start();





}

请尽早帮助我。如果不解决此问题,我将无法继续我的进一步工作

4

1 回答 1

0

尝试以下方法来显示带有 webView 的进度对话框

  webView.setWebViewClient(new WebViewClient() {

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

           @Override
           public void onPageFinished(WebView view, String url) {

            //HIDE PROGRESS DIALOG LOADING IT HAS FINISHED
          }

        });

它肯定会帮助你

于 2013-02-17T12:33:11.883 回答