Problem using ProgressDialog with onCreateDialog / onPrepareDialog

I use the following code to create a ProgressDialog (inside my Activity ):

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case DIALOG_LOOKUP:
            return new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
    }
    return null;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
        case DIALOG_LOOKUP:
            dialog.setCancelable(true);
            dialog.setTitle(R.string.dialogLookup_title);
            ((ProgressDialog)dialog).setMessage(getResources().getString(R.string.dialogLookup_message));
            dialog.setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    Toast.makeText(MyActivity.this, "canceled", Toast.LENGTH_SHORT).show();
                }
            });
            break;
    }
}

The problem is that it doesn't actually set the header and puts it in some weird double box.

This gives me this:

bad progress

but I expect something more:

good progress

Any ideas?

+4
source share
1 answer

I just tried your sample and seems to have changed from ProgressDialog.STYLE_SPINNERto ProgressDialog.STYLE_HORIZONTAL, fixed an odd double-box problem.

And it also displays the title and text.

Edit:

You pass ProgressDialog.STYLE_SPINNERin the constructor ProgressDialog.

In the doc document, the second argument is the topic identifier.

ProgressDialog setProgressStyle to ProgressDialog.STYLE_SPINNER

case DIALOG_LOOKUP:
     ProgressDialog pdlg = new ProgressDialog(this);
     pdlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
     return pdlg;
+6

All Articles