public class progress extends Activity {
public final static int TASK_LOOP_COMPLETE = 0;
ProgressDialog pd;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pd = ProgressDialog.show(this, "", "loading...", true, true);
new Thread() {
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
messageListener.sendEmptyMessage(TASK_LOOP_COMPLETE);
}
}
}.start();
}
private Handler messageListener = new Handler(){
public void handleMessage(Message msg) {
switch(msg.arg1){
case TASK_LOOP_COMPLETE:
pd.dismiss();
break;
}
}
};
}
这是一个线程,会一直运行,你把
读取某一网页的xml数据并将其绑定于listview进行显示 放在这儿会一直运行,并且这个操作比较费时,这样写肯定会有问题啦
Android进度条编程是在线程中更新进度,或用消息机制发消息给来更新进度条