2012-10-11 77 views
2

我想在我的應用程序中添加一個加載器對話框到我的webview。那麼,你能幫我解決這個問題嗎?如何將加載器對話框添加到我的webview?

這是我的WebView 代碼

public class AlTibbiWebViewActivity extends Activity { 

private WebView wv; 
private Intent incomingIntent = null; 
private WebViewClient wvc = new WebViewClient() { 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     wv.loadUrl(url); 
     return true; 
    } 

}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.web_view); 
    this.wv = (WebView) findViewById(R.id.webView); 
    this.wv.setWebViewClient(wvc); 
    wv.getSettings().setJavaScriptEnabled(true); 
    this.incomingIntent = getIntent(); 
    String urlToLoad = incomingIntent.getExtras().getString("urlToLoad"); 

    //EXTRA HEADER MAP (remove header from web view) 

    Map<String, String> aMap = new HashMap<String, String>() ; 
    aMap.put("app", "no"); 
    //myMap = Collections.unmodifiableMap(aMap); 
    wv.loadUrl(urlToLoad , aMap); 

} 

回答

4
webView.setWebViewClient(new WebViewClient() { 

     public boolean shouldOverrideUrlLoading(WebView view, String url) {    
      view.loadUrl(url); 
      return true; 
     } 
     public void onLoadResource (WebView view, String url) { 
      if (progrDialog == null) { 
       progrDialog = new ProgressDialog(YourActivity.this); 
       progrDialog.setMessage("Loading..."); 
       progrDialog.show(); 
      } 
     } 
     public void onPageFinished(WebView view, String url) { 
      try{ 
      if (progrDialog.isShowing()) { 
       progrDialog.dismiss(); 
       progrDialog = null; 
      } 
      }catch(Exception exception){ 
       exception.printStackTrace(); 
      } 
     } 
    }); 
+0

我有小錯誤我的朋友:)我把代碼只是像你的文章,但我得到的錯誤,在過去}); – aziz

+0

我應該在哪裏將我的代碼放在我的代碼中? – aziz

+0

在oncreate方法 – Jamshid