Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 SimpleExpandableListAdapter 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. :-)

like image 770
Christopher Perry Avatar asked Nov 24 '25 16:11

Christopher Perry


2 Answers

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

like image 52
ud_an Avatar answered Nov 28 '25 04:11

ud_an


Just use this simple line:

mProgressDialog = ProgressDialog.show(context, "", "msg to show", true);

You can dismiss it with:

mProgressDialog.dismiss();
like image 24
Macarse Avatar answered Nov 28 '25 04:11

Macarse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!