package com.example.asynctask;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Contacts.Intents.Insert;
import android.widget.ProgressBar;
public class ProgressBarTest extends Activity{
private ProgressBar pb;
private myAsyncTask ptask;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pb=(ProgressBar) findViewById(R.id.progressBar1);
ptask=new myAsyncTask();
ptask.execute();
}
class myAsyncTask extends AsyncTask<Void, Integer, Void>{
protected Void doInBackground(Void... params) {
for(int i=0;i<100;i++){
publishProgress(i);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO 自动生成的方法存根
super.onProgressUpdate(values);
pb.setProgress(values[0]);
}
}
}