0

I have this following spinner in my main activity My problem is that the spinner's value is required when submitting but i want its default value to be empty so i put in my arrays.xml an item with empty value. so when the app is lunched it will show a empty spinner. The problem is that when they click the spinner and the drop down display the first selection is empty.

enter image description here

my solution is to put the first data as "Select" but is there a way that the value would be empty like in html select tag?

<option value="">Select</option>
<option value="data 1">data 1</option>

on android xml is this possible? or how to do it? i tried this but still not working. it passes the value "Select"

   <item value="">Select</item>
   <item value="data 1">data 1</item>

my spinner

<Spinner
                android:id="@+id/spinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:entries="@array/spinner_arr"
                android:tag="relation" />

my arrays.xml

<string-array name="spinner_arr">
    <item></item>
    <item>data 1</item>
    <item>data 2</item>
    <item>data 3</item>
    <item>data 4</item>
    <item>data 5</item> 
</string-array>
Snippet
  • 1,522
  • 9
  • 31
  • 66

1 Answers1

0

Try using the prompt attr of Spinner, if that's not work you'll have to craete some adapter of your own. take a look here: How to make an Android Spinner with initial text "Select One"

Community
  • 1
  • 1
shem
  • 4,686
  • 2
  • 32
  • 43