I am using Spinner
for displaying some values. And the strange issue is that
The dropdown is displaying correctly, but when I select any item from dropdown, is not displayed in the box.
And the strange thing is this functionality is working on all Android Operating Systems before 6.0.1(i.e. 6.0.0 and previous)
.
I have also tried AppCompatSpinner
and the result is same.
main.xml:
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:entries="@array/values" />
Main.java:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setSelection(5); // Not displaying 5th item, Yes! there are more than 5 items.
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
spinner.setSelection(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
spinner.setSelection(5);
}
});