开发者

Android: Progress Dialog Doesn't Show

开发者 https://www.devze.com 2023-01-13 08:45 出处:网络
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 ExpandableListActi

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消