0

我有以下代码。我在一个活动中使用了 4 个片段。该片段有一个 webView。但是如您所知,为片段准备所有数据需要很长时间。所以我想在数据准备时使用进度对话框。是的,我打电话给它,现在只是在进度完成后试图关闭progressDialog。但我觉得它很喜欢我。哪儿也不去。有什么帮助吗??谢谢。

(注意:我已经从我的项目中删除了代码。现在重新添加到这里,所以我可能犯了一些小错误。不要坚持下去。)

   public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){

    final ProgressDialog pd = new ProgressDialog(getActivity()) ;       
    if (wv != null) {
         wv.destroy();
    }     
     wv = new WebView(getActivity());
     wv.getSettings().setJavaScriptEnabled(true);                     


     wv.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {pd = ProgressDialog.show(this, "", "Loading...", true);
             Log.e("Progress:", ""+progress);
             if(progress == 100){pd.dismiss();}
            }

        });


     wv.setWebViewClient(new WebViewClient(){

         @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                Log.e("Connection:", "NO");
            }
      @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {   
                view.loadUrl(url);
                return true;
            }
     });    

     wv.loadUrl("http://mobile.twitter.com/Yali_Spor");  


     wva = true;

     return wv;

}
4

2 回答 2

1

这样做-

   final ProgressDialog pd;      
if (wv != null) {
     wv.destroy();
}     
 wv = new WebView(getActivity());
 wv.getSettings().setJavaScriptEnabled(true);                     


 wv.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {pd = ProgressDialog.show(this, "", "Loading...", true);
         Log.e("Progress:", ""+progress);
         if(progress == 100){pd.dismiss();}
        }

    });
于 2013-09-03T10:46:21.447 回答
1

On each progress change you make a new ProgressDialog so you have a lot of dialogs at the end eventually and you only dismiss the top one this way when progress is 100

于 2013-09-03T10:50:54.923 回答