2

Well first of all This is not android.widget.Spinner it's AppCompatSpinner

how to add hint of AppCompatSpinner i'm getting a string-array from String.xml

So my question is how to i take 1st String as a Hint

Below layout.xml file :

<android.support.v7.widget.AppCompatSpinner
                    android:id="@+id/spStates"
                    style="@style/TextLabelBookBlack"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginBottom="@dimen/_4sdp"
                    android:layout_marginTop="@dimen/_4sdp"
                    android:entries="@array/us_states"
                    android:scrollbars="none"/>

Below is String.xml

<string-array name="us_states">
        <item>States</item>
        <item>Alabama,AL</item>
        <item>Alaska,AK</item>
        <item>American Samoa,AS</item>
        <item>Arizona,AZ</item>
        <item>Arkansas,AR</item>
        <item>California,CA</item>
        <item>Colorado,CO</item>
        <item>Connecticut,CT</item>
</string-array>

in String.xml 1st item is States so i want to take States as a hint so how to i take it.

Rob
  • 26,989
  • 16
  • 82
  • 98
Ali
  • 3,346
  • 4
  • 21
  • 56

2 Answers2

1

May be you can use an edit text and set a hint to it..when users select an item display it in the edit text ..just keep the spinner below the edit text in xml file ...and fire onclick event of spinner when clicked on edit text(basically you just need to hide/show the dropdown)

Harsh Agrawal
  • 597
  • 3
  • 12
1

You might be interested in the prompt attribute of the Spinner class.

Rainmaker
  • 10,294
  • 9
  • 54
  • 89