我有一個ListActivity
需要大量的數據通過Thread
進行處理。我想在background
中完成工作時顯示Dialog
。但是,Dialog
直到視圖加載完成纔會顯示。我在正常的activity
上使用這種方法,它工作(Dialog
彈出,工人開始,工人結束,Dialog
解散)。工作完成後,會發送一條消息handler
加載view
並解除Dialog
。ListActivity和Dialogs
這裏是我的代碼:
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
initViewProperties();
dialogCode = 0;
showDialog(dialogCode);
}
@Override
protected Dialog onCreateDialog(int id) {
int resID = getResources().getIdentifier(getCfrFile(), "raw", getPackageName());
progDialog = new ProgressDialog(this);
switch (dialogCode) {
case 0:
progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDialog.setMessage(getCurrentTitle());
break;
case 1:
progDialog.setMessage("Loading CFR");
break;
default:
break;
}
try {
// do the work here
xmlListRowFactoryHelper = new AcmListViewFactoryHelper(handler, resID, this, xpathBuilder(false), "title") ;
xmlListRowFactoryHelper.run();
} catch (Exception e) {
e.printStackTrace();
}
return progDialog;
}
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int total = msg.getData().getInt("total");
progDialog.setProgress(total);
if (total <= 0){
xmlListRowFactoryHelper.setState(AcmTableRowFactoryHelper.DONE);
// load the view here
loadListView();
}
}
}