在Activity的onCreate函数中添加以下代码:
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
mDlg = ProgressDialog.show(AListTest.this, "My Progress", "This is the progress.");
new Thread(){
public void run(){
try{
sleep(3000);
}
catch(Exception e){
e.printStackTrace();
}
finally{
mDlg.dismiss();
}
}
}.start();
}
});
运行效果图如下:

本文介绍了如何在Android Activity的onCreate函数中添加代码实现一个简单的进度条显示功能,包括创建按钮、设置点击事件、显示进度对话框并控制其生命周期。
7473

被折叠的 条评论
为什么被折叠?



