Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

imageview - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...