2012-07-19 57 views
1

我在加載webview對話框時遇到了問題。我的對話是dismis但我必須再次等待一些秒鐘,顯示完整的WebView ..我想的是,如果加載對話框是dismis的WebView做..這是我的WebView代碼:在android中加載對話框

progressBar = new ProgressDialog(this); 
webView = (WebView) findViewById(R.id.webView1); 
webView.getSettings().setJavaScriptEnabled(true); 
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 

final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
progressBar = ProgressDialog.show(WebViewFacebook.this, "Loading", "Please wait for a moment..."); 

webView.setWebViewClient(new WebViewClient() { 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     view.loadUrl(url); 
     return true; 
    } 

    public void onPageFinished(WebView view, String url) { 
     if (progressBar.isShowing()) { 
      progressBar.dismiss(); //--> this progressbar always dismis although mw webview not done >< 
     } 
    } 

    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
     alertDialog.setTitle("Error"); 
     alertDialog.setMessage(description); 
     alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       //return; 
       finish(); 
      } 
     }); 
     alertDialog.show(); 
    } 
}); 
webView.loadUrl(strurl); 
+0

我的問題是loadingdialog dismis雖然網頁流量不這樣做,所以我必須等待一段第二,看網頁...... – 2012-07-19 11:14:53

回答

1

見下代碼

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    view = (WebView) findViewById(R.id.WebView01); 
    view.setBackgroundColor(0); // set the background transparent 

    progressDialog = ProgressDialog.show(view.getContext(), "Loading...", "Loading..."); 
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER ); 

    view.setWebChromeClient(new MyWebChromeClient()); 
    view.getSettings().setJavaScriptEnabled(true); 
    view.setWebViewClient(new MyWebViewClient()); 
    view.loadUrl("http://www.XXX.XXX"); 

} 

然後創建班組長

private class MyWebViewClient extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    { 
     view.loadUrl(url); 
     return true; 
    } 
} 


private class MyWebChromeClient extends WebChromeClient { 

    @Override 
    public void onProgressChanged(WebView view, int newProgress) { 
     if(progressDialog!=null){ 
      if (newProgress >=80) { 
       progressDialog.dismiss(); 
      } else { 
       progressDialog.setMessage(newProgress + " % loaded"); 
      } 
     } 
     super.onProgressChanged(view, newProgress); 
    } 
} 
+0

好吧,我會try..i將通知結果 – 2012-07-19 11:40:03

+0

仍然是相同的..我必須等待一些第二雖然我的對話是dismis buat webview未完成>< – 2012-07-19 11:46:47

+0

你可以做newProgress> = 80到100並嘗試 – Nirali 2012-07-19 11:48:07

相關問題