Android ProgressDialog with setContentView
Asked Answered
R

3

9

I've read a hell of a lot about this, and can't see anyone who's done or tried it before.

So I've got an object that extends ImageView, then within this I call a progress dialog and set the progress dialogs's content to the imageview (i.e. attempting to draw the progress dialog in the imageview..view.)

    loadingProgressDialog.setContentView(this); //this is: LoaderImageView extends ImageView        
    loadingProgressDialog.setIndeterminate(true);
    loadingProgressDialog.show();

And I get the error: requestFeature() must be called before adding content

Now I've seen this error before on loads of posts and yes the answer seems obvious. I've tried to set all the features:

loadingProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
loadingProgressDialog.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
loadingProgressDialog.getWindow().requestFeature(Window.FEATURE_PROGRESS);
loadingProgressDialog.getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

But first I don't understand why I need this? And second none of them work anyway!

So the question is can I set the ProgressDialog contentView to an ImageView? If so what have I gotten wrong?

Randolph answered 4/12, 2010 at 0:40 Comment(0)
R
0

Got it.

The clue was in the class names, don't use ProgressDialog ( http://developer.android.com/reference/android/app/ProgressDialog.html ) when you don't need a dialog!

I changed my implementation to use: ProgressBar ( http://developer.android.com/reference/android/widget/ProgressBar.html ) and it works great.

Cheers for the ear anyway!

This is why I was looking for it for:

http://www.anddev.org/novice-tutorials-f8/imageview-with-loading-spinner-t49439.html

Tutorial showing how you can have a Spinner whilst an image is loading. Enjoy

Randolph answered 4/12, 2010 at 11:26 Comment(0)
C
44

I made it; in fact, it's very easy; using

loadingProgressDialog.setContentView(this) 

after

loadingProgressDialog.show() 

The following lines of code are unnecessary:

loadingProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
loadingProgressDialog.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
loadingProgressDialog.getWindow().requestFeature(Window.FEATURE_PROGRESS);
loadingProgressDialog.getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

that's to say:

loadingProgressDialog.setIndeterminate(true);
loadingProgressDialog.show();
loadingProgressDialog.setContentView(this); //this is: LoaderImageView extends ImageView 

that is enough.

I hope this can help other people looking for answer about this question.

Caruthers answered 9/4, 2012 at 8:57 Comment(3)
Strange, putting setContentView() AFTER .show() got it to work in my situation. Interesting. Thanks!Bur
Whaao! Could never have guessed that setContentView be placed after .show()Sheetfed
This is definitely the correct answer to the question.Resolve
S
0

If you read the progressDialog developer doc it says "A dialog showing a progress indicator and an optional text message or view. Only a text message or a view can be used at the same time."

It looks like you are trying to do both. Possibly the cause of your issue.

Stephanestephani answered 4/12, 2010 at 1:11 Comment(1)
I can see what your saying, this doesn't seem to be the error I've updated the original post. I got my idea from developer.android.com/guide/topics/ui/dialogs.html#CustomDialogRandolph
R
0

Got it.

The clue was in the class names, don't use ProgressDialog ( http://developer.android.com/reference/android/app/ProgressDialog.html ) when you don't need a dialog!

I changed my implementation to use: ProgressBar ( http://developer.android.com/reference/android/widget/ProgressBar.html ) and it works great.

Cheers for the ear anyway!

This is why I was looking for it for:

http://www.anddev.org/novice-tutorials-f8/imageview-with-loading-spinner-t49439.html

Tutorial showing how you can have a Spinner whilst an image is loading. Enjoy

Randolph answered 4/12, 2010 at 11:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.