I have some data that I upload to the database the first time a user logs into mine Activityand want to show ProgressDialogwhile this data is being loaded for the first time. My activity is this ExpandableListActivity, and I do not create SimpleExpandableListAdapteror call setListAdapterby passing my adapter until I’m sure that the data is actually there. My onCreatelooks like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCategoryDbHelper = new CategoryDBHelper(this);
CategoryDbBuilder builder = new CategoryDbBuilder(this);
if (!builder.hasCategoriesInTable()) {
showDialog(PROGRESS_DIALOG_ID);
builder.fillDbWithDefaultCategories();
removeDialog(PROGRESS_DIALOG_ID);
}
populate();
}
I rewrote onCreateDialogas such:
@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;
}
The method populate()reads the database and configures my list adapter, and then calls setListAdapter.
It seems like it should be simple, but it becomes a huge pain. Any help would be greatly appreciated. :-)