【发布时间】:2010-08-30 01:31:01
【问题描述】:
我有一些数据在用户第一次输入我的Activity 时加载到数据库中,并希望在第一次加载这些数据时显示ProgressDialog。我的活动是ExpandableListActivity,在我确定数据确实存在之前,我不会创建SimpleExpandableListAdapter 或调用setListAdapter 传递我的适配器。我的onCreate 看起来像这样:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCategoryDbHelper = new CategoryDBHelper(this);
// Build default categories... if not there yet
CategoryDbBuilder builder = new CategoryDbBuilder(this);
if (!builder.hasCategoriesInTable()) {
showDialog(PROGRESS_DIALOG_ID);
builder.fillDbWithDefaultCategories();
removeDialog(PROGRESS_DIALOG_ID);
}
populate();
}
我已经这样覆盖了onCreateDialog:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case PROGRESS_DIALOG_ID: {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Loading categories for the first time. Please wait...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
return dialog;
}
}
return null;
}
populate() 方法读取数据库并设置我的列表适配器,然后调用setListAdapter。
这看起来应该很简单,但结果却是一个巨大的痛苦。任何帮助,将不胜感激。 :-)
【问题讨论】: