I have implemented the spinner by populating the array list through database.I can get and show the array list in my spinner array adapter but if I select the item in spinne
This happens occasionally, I guess it's a bug but there's a workaround which is funny but just do it,
In the property bar of the spinner set the background to a different color,
In your .xml where you have your spinner, set:
android:background="@android:drawable/spinner_background_material"
run the code it will generate an error saying the background is private
delete the line of the android:background
in the .xml and run the code again,your spinner should work fine showing all the values, if it doesn't take the extra step of setting background tint to a different color preferably black.
Run it again.
use android:spinnerMode="dropdown"
attribute in your declared Spinner
element's xml
Well this also happens if the context is not properly given. I was using getApplicationContext()
where as it needs getBaseContext()
.
Generally spinners gets selected by default when they are used ,so try to set blank,or any other data to first position that is zero position, you will get exact position of you selected item .
I got same problem and solved by adding notifyDataSetChanged()
after binding data in Spinner.
First of all I have bind adapter with Blank ArrayList
then getting List of Items from Server and added to that List but forgot to notifyDataSetChanged()
after updated List.
just add adapter.notifyDataSetChanged();
after updating list.
Hope it will helpful.
I was using hardcoded value for width and height. After changing to wrap_content it works.