问题
I have a spinner with three items in it
<string-array name="menuitems">
<item>one</item>
<item>two</item>
<item>three</item>
</string-array>
Then I set up my spinner like this
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.menuitems, R.layout.spinnerstyle);
adapter.setDropDownViewResource(R.layout.spinnerdropdownstyle);
spinner.setAdapter(adapter);
The spinner displays like this
One
One
Two
Three
My problem is for this spinner I don't want to display the selected item I want this
One
Two
Three
And obviously if two were selected only one and three would appear in the dropdown. I did search for this but couldn't figure out a way to get that affect I tried changing the menuitems array on selection but if I removed the item from there it wouldn't draw it in the selection. I assume there is a fairly easy way to get this affect.
thanks for any help.
回答1:
Write a custom SpinnerAdapter which returns the items from the menu excluding the selected one.
回答2:
You can try to set the promt in the xml to "One" like this:
<Spinner android:id="@+id/spinnerTest"
android:layout_marginLeft="50px"
android:layout_width="fill_parent"
android:drawSelectorOnTop="true"
android:layout_marginTop="5dip"
android:prompt="@string/SelectOne"
android:layout_marginRight="30px"
android:layout_height="35px"
/>
Then you should override the onItemClick methode and set the text of your variable in "On nothing selected".
来源:https://stackoverflow.com/questions/14878533/android-spinner-dont-draw-selected-item