public void onCreate(Bundle savedInstanceState) { |
super .onCreate(savedInstanceState); |
setContentView(R.layout.main); |
Button mButton1 = (Button) findViewById(R.id.myButton1); |
mButton1.setOnClickListener(myShowProgressBar); |
} |
Button.OnClickListener myShowProgressBar = new Button.OnClickListener() { |
public void onClick(View arg0) { |
// 显示Progress对话框 |
ProgressDialog myDialog = ProgressDialog.show(Demo. this , "title" , |
"message" , true ); |
mTextView1.setText(strDialogBody); |
new Thread() { |
public void run() { |
try { |
/* 在这里写上要背景执行的程序片段 */ |
/* 为了明显看见效果,以暂停3秒作为示范 */ |
sleep( 3000 ); |
} catch (Exception e) { |
e.printStackTrace(); |
} finally { // 卸除所建立的myDialog对象。 |
myDialog.dismiss(); |
} |
} |
}.start(); /* 开始执行线程 */ |
} |
/* End: public void onClick(View arg0) */ |
}; |