How to add Title in Spinner in android [duplicate]
I have a problem I have design a spinner and add items(i.e. states) on it. Now I want to show "SELECT STATES" on main Screen only once. When we click on that spinner it will hide this text("SELECT STATES") and should show the list of the states.
Thanks in Advance.
Easy: spinner.setPrompt("Title"); or xml: android:prompt="@string/title"
I don't think it has such attribute, even google uses a textview to show the title in the example: http://developer.android.com/resources/tutorials/views/hello-spinner.html
If you really want to do it that way, you can add the String "SELECT STATES" in the first slot of the list, and then remove it after the first item selection.
Here is my favourite solution to the problem - How to make an Android Spinner with initial text “Select One”
I'm sorry it is very long, so I'm not keen to repost it here again - please check it out on the link.
The nice part is that I was able to use his code without any changes at all.
精彩评论