开发者

how to set a title for spinner which is not selectable..? [duplicate]

开发者 https://www.devze.com 2023-03-13 21:13 出处:网络
This question already has answers开发者_StackOverflow社区 here: How to make an Android Spinner with initial text "Select One"?
This question already has answers开发者_StackOverflow社区 here: How to make an Android Spinner with initial text "Select One"? (36 answers) Closed 10 years ago.

I have spinner but in it only selectable items are shown as default title..

is there any way i can set title which doesn't appear when spinner unfolds...


You will have to set the prompt attribute of spinner.

<Spinner   android:id="@+id/discuss_about_spinner"  
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"
           android:prompt="@string/discuss_about_header"
           android:layout_below="@+id/what_time_layout">
</Spinner>

Programmatically set title to Spinner

spinner.setPrompt("Title");

I don't know what the reason is, prompt don't support direct substitution of a string value. Instead you must have your string in strings.xml.


I just realized what you were trying to do. You want the Spinner "button" to have a title. Something like "- Select One -", correct?

If that is indeed the case, here is how I accomplished this. Don't use a spinner. Instead, use a button and style with the title to look like a spinner (will have to find how I did this). When the user clicks the button, open a "select one" dialog and style it to look like a spinner's dialog. I'll try to put a code sample up shortly.


I'm afraid this is not available out-of-the-box. You'll need to implement this yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号