Android: progress dialog and thread
//不顯示title
ProgressDialog _progressDialog = ProgressDialog.show(
FriendListViewActivity.this, "", getString( R.string.progressing )
, true, false );
//顯示title
ProgressDialog _progressDialog = ProgressDialog.show(
FriendListViewActivity.this, "title mssage", getString( R.string.progressing )
, true, false );
//建立執行緒
new Thread(){
@Override
public void run(){
try{
//可改為欲執行的程式碼
Thread.sleep(5000);
}
catch (Exception e){
e.printStackTrace();
}
finally{
pDialog.dismiss(); //關閉dialog
}
}
}.start(); //開始執行緒
//如果有欲修改到UI的內容部分,加上
runOnUiThread(new Runnable() { // Correct!!
public void run() {
//modify View object
textView.setText("test");
}
});
Reference:
http://kerkerj.twgg.org/2012/04/android-thread-ui-update.html
Comments
Post a Comment