加载网页/android时的进度条

加载网页/android时的进度条,android,Android,我想知道是否可以包含一个进度条,这样当用户按下某个按钮时,它会加载页面,但在加载页面之前进度条会显示出来。这是我的密码 public class Sites extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sites); View.OnClickL

我想知道是否可以包含一个进度条,这样当用户按下某个按钮时,它会加载页面,但在加载页面之前进度条会显示出来。这是我的密码

public class Sites extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.sites);

  View.OnClickListener openIt = new View.OnClickListener() {
    public void onClick(View v) {
        startActivity(new Intent(
              Intent.ACTION_VIEW,
              sites.this,   
              com.abc.example.Address.class
         ));
    }
  };

  Button sites= (Button) findViewById(R.id.siteA);
  sites.setTag(Uri.parse("http://sitea.com/")); 
  sites.setOnClickListener(openIt);     

  sites = (Button) findViewById(R.id.siteB);
  sites.setTag(Uri.parse("http://siteb.com/"));
  sites.setOnClickListener(openIt);

  sites = (Button) findViewById(R.id.siteC);
  sites.setTag(Uri.parse("https://sitec.com/"));
  sites.setOnClickListener(openIt);

  sites = (Button) findViewById(R.id.siteD);
  sites.setTag(Uri.parse("https://sited.com/"));
  sites.setOnClickListener(openIt);
}
看。基本上,AsyncTask是一个在后台加载数据的模板,同时具有更新进度条的调用。以下是google关于如何运行异步任务的示例:

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile(urls[i]);
             publishProgress((int) ((i / (float) count) * 100));
         }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }
私有类下载文件任务扩展异步任务{
受保护的长doInBackground(URL…URL){
int count=url.length;
长totalSize=0;
for(int i=0;i