0

こんにちは、私は Android アプリを持っており、アプリの Web ビューで ProgressDilog を作成しようとしています。サイトが読み込まれているとき、アクティビティのタイトルではすべてがうまく機能しますが、進行中のダイアログでは停止できません。これは私のコードです:

mainWebView.setWebChromeClient(new WebChromeClient() {


           public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);
                 progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...");



                if(progress == 100)
                {   
                  activity.setTitle(mainWebView.getTitle());
                      progressDialog.dismiss();
                }   


            }


        });

しかし、progressDialog.dismiss(); 動作しません:(

4

3 に答える 3

4

PD.show()毎回ではなく、一度だけ行うべきだと思いますonProgressChanged()。おそらく 12 個の PD が実行されています。

編集:より正確に言えばpd.show()、何をしていても始めるときに行うことです。onProgressChanged()プログレスバーをいくつかのコンテンツ(ロードされたパーセントなど)で更新しますsetProgress().

于 2012-08-16T12:09:19.180 に答える
1

すべてのステップで ProgressDialog を表示するこの簡単なデモを参照してください。

public class AsyntaskActivity extends Activity {
 final Activity activity = this;
 private WebView webView; 
 private AlertDialog alert; 
 private Builder builder;
 protected void onCreate(Bundle savedInstanceState) {     
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.main);
     webView = (WebView)findViewById(R.id.tview);

     webView.setWebViewClient(new WebViewClient(){          
         @Override         
         public void onLoadResource(WebView view, String url) {             
             super.onLoadResource(view, url);         
         }          
         @Override         
         public void onPageFinished(WebView view, String url) {             
             super.onPageFinished(view, url);             
             alert.setTitle("Finish Loading. . ."); 
             alert.dismiss();
         }          
         @Override         
         public void onPageStarted(WebView view, String url, Bitmap favicon) {             
             super.onPageStarted(view, url, favicon);             
             alert.setTitle("Start Loading. . . ");         
        }      
    });     
     webView.setWebChromeClient(new WebChromeClient(){});     
     webView.loadUrl("http://www.google.com");     
     builder=new AlertDialog.Builder(this);     
     builder.setTitle("Loading...");     
     alert=builder.create();     
     alert.show(); 
} 

@Override protected void onDestroy() {     
    super.onDestroy();  
}  
@Override protected void onPause() {     
    super.onPause(); 
} 

}

于 2012-08-16T13:40:40.097 に答える
0
public void onProgressChanged(WebView view, int progress)
        {
            activity.setTitle("Loading...");
            activity.setProgress(progress + 100);
             progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...");



            if(progress == 100)
            {   
              activity.setTitle(mainWebView.getTitle());
                  progressDialog.dismiss();
            }   


        }


    });
于 2012-08-16T12:29:16.077 に答える