views:

944

answers:

1

I'm using 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 isn't actually setting the title and is putting it in some weird double-box.

It's giving me this:

bad progress

but I'm expecting something more like this:

good progress

Any ideas?

+2  A: 

I just tried your sample and it seems changing from ProgressDialog.STYLE_SPINNER to ProgressDialog.STYLE_HORIZONTAL fixed the weird double-box problem.

And it also displays the title and text.

Edit:

You are passing ProgressDialog.STYLE_SPINNER in the ProgressDialog constructor.

From the doc, the 2nd argument is a theme id.

You will have to create a ProgressDialog object and use the setProgressStyle to ProgressDialog.STYLE_SPINNER

case DIALOG_LOOKUP:
     ProgressDialog pdlg = new ProgressDialog(this);
     pdlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
     return pdlg;
ccheneson
D'oh... how could I have missed that? I'm still not getting a title though.
fiXedd
Well, for some reason I had to move my `setTitle()` into `onCreateDialog()`, but that seems to have done it. Thanks for the help.
fiXedd