Android: Progress Dialog Doesn't Show
I have some data I load into the database the first time a user enters my Activity
, and want to show a ProgressDialog
while this data is loaded for the first time. My Activity is an ExpandableListActivity
and I don't create the Si开发者_StackOverflow中文版mpleExpandableListAdapter
or call setListAdapter
passing my adapter until I'm sure the data is actually there. My onCreate
looks like this:
@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();
}
I've overwritten onCreateDialog
as 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 populate()
method reads the database and sets up my list adapter, then calls setListAdapter
.
This seems like it should be simple, but it's turning out to be a huge pain. Any help would be appreciated. :-)
Use AsynTask put your database loading processing in background function and in post execution display result. and there is another function to processing something until background process running here is example of asynTask
Android - I want to show file upload progress to the user
Just use this simple line:
mProgressDialog = ProgressDialog.show(context, "", "msg to show", true);
You can dismiss it with:
mProgressDialog.dismiss();
精彩评论