2012-02-07 11 views
5

Tôi đang sử dụng chế độ xem web để hiển thị các trang html và tôi muốn hiển thị hộp thoại tiến trình cho đến khi trang được tải. Khi đã xong, hộp thoại sẽ biến mất. Tôi đã sử dụng AsyncTask cho điều này, nhưng hộp thoại không hiển thị. Xem mã của tôi bên dưới:Cách hiển thị hộp thoại tiến trình trong khi trang HTML được tải trong WebView

class DownloadAysnc extends AsyncTask<String, String, Void> 
    { 
    ProgressDialog progressDialog; 
     @Override 
      protected void onPreExecute() { 
      super.onPreExecute(); 
      progressDialog = ProgressDialog.show(OverView.this, "", "Please Wait ..."); 
     } 

     @Override 
      protected Void doInBackground(String... arg0) { 
      webView.loadUrl("http://marico.com/html/investor/overview.php"); 
     return null; 
     } 

     @Override 
      protected void onPostExecute(Void result){ 
      super.onPostExecute(result); 
      progressDialog.dismiss(); 
     } 
    } 

Và nếu tôi nhờ trợ giúp của tài liệu google để hiển thị trang web, thì Thẻ HTML được hiển thị, nhưng không hiển thị trang. Dưới đây là mã:

String url = "http://google.co.in/"; 
String googleDocsUrl = "http://docs.google.com/viewer?url="+url; 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse(googleDocsUrl), "text/html"); 
startActivity(intent); 

this.myWebView.loadUrl(googleDocsUrl); 

Ai đó có thể giúp tôi với điều này?

Trả lời

13

Sử dụng mã này:

webView.setWebViewClient(new WebViewClient() { 
    ProgressDialog prDialog; 
    @Override 
    public void onPageStarted(WebView view, String url, Bitmap favicon) { 
     prDialog = ProgressDialog.show(Activity.this, null, "loading, please wait..."); 
     super.onPageStarted(view, url, favicon); 
    } 

    @Override 
    public void onPageFinished(WebView view, String url) { 
     prDialog.dismiss(); 
     super.onPageFinished(view, url); 
    } 
}); 

webView.loadUrl(url); 
+0

tôi nên đặt gì (Chế độ xem WebView, URL url, ** Biểu tượng bitmap **) Nó cho tôi lỗi thời gian biên dịch tại dòng ** Hình nền bitmap **. Tôi nên đặt cái gì. –

+0

Cảm ơn rất nhiều !! –

+0

cảm ơn rất nhiều người đàn ông ... nó đã cứu tôi – Noman

1

Bạn có thể thử sau mã,

progDailog = ProgressDialog.show(loginAct,"Process ", "please wait....",true,true); 

new Thread (new Runnable() 
{ 
    public void run() 
    { 
     // your code goes here 
    } 
}).start(); 

Handler progressHandler = new Handler() 
{ 

    public void handleMessage(Message msg1) 
    { 
     progDailog.dismiss(); 
    } 
} 
2

Bạn có thể hiển thị các Progress của WebView trong Title Bar của WebView. Here là ví dụ hoàn chỉnh cho cùng một hiển thị ProgressStatus trong thanh Title của WebView.

3
v.setWebChromeClient(new WebChromeClient(){ 
     @Override 
     public void onProgressChanged(WebView view, int newProgress) { 
      WebView v=(WebView)findViewById(R.id.wv); 
      //Toast.makeText(mContext, v.getUrl() + newProgress +"uploading...", Toast.LENGTH_SHORT).show(); 
      ProgressBar s=(ProgressBar)findViewById(R.id.progressBar1); 
      s.setMax(100); 
      s.setProgress(newProgress); 
      if(newProgress==100){       
       v.setVisibility(0); 
       //Toast.makeText(mContext, "upload finished...", Toast.LENGTH_SHORT).show(); 
     }else{ 
       v.setVisibility(8); 
       //Toast.makeText(mContext, "uploading...", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 
+1

Chào mừng bạn đến với Stack Overflow. Bạn có thể vui lòng xây dựng thêm câu trả lời của bạn. –

+1

Đặc biệt khi bạn trả lời một câu hỏi cũ đã được chấp nhận và trả lời bình chọn, hãy cung cấp một số giải thích. Câu trả lời của bạn khác nhau như thế nào và tốt hơn câu trả lời được chấp nhận trước đó? –