Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProgressDialog with setContentView

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?

like image 636
Blundell Avatar asked Dec 04 '10 00:12

Blundell


People also ask

Is ProgressDialog deprecated?

ProgressDialog 's look can be replicated by placing a ProgressBar into an AlertDialog . You can still use it, but Android does not want you to use it, that is why it is deprecated.

How do I change font size in progress dialog android?

You can use a spannable string and set the color and size for the spannable string. Use the spannable string to set text color and size.

How do I instantiate an object for ProgressDialog class?

In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this); Now you can set some properties of this dialog.


1 Answers

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.

like image 81
Mejonzhan Avatar answered Oct 23 '22 08:10

Mejonzhan