Spinner does not display the selected item
PROBLEM
My problem is that after changing the data in my SpinnerArrayAdapter
my my Spinner
does not respond to clicks of elements on dropDownList
. However, after changing the orientation, everything works fine (?!). EDIT: I noticed that it catches clicks, but doesn't display / show on Spinner
. Since after changing the orientation, the selected item appears onSpinner
DESIGN
I have AutoCompleteTextView(ACTV)
linked to AutoCompleteAdapter implementing Filterable
. After entering some data, the ACTV
result is passed to SpinnerArrayAdapter
which is connected to Spinner
.
B is AutoCompleteAdapter
installed customListener
, which is connected to SpinnerArrayAdapter
and is responsible for transferring data between them.
The reason for this design is that the user can have a two-step choice. One when dropping out when choosing data from ACTV
, and the second in case he changes his mind. This way you can put a POSTCODE in the select area ACTV
that connected and changed the province when you skipped / changed the mind without forcing you to re-enter POSTCODE.
CODE
This is the part that is responsible for changing the data inside SpinnerArrayAdapter
.
@Override
public void setCitiesFromPostcode(ArrayList<String> cities) {
this.clear();
this.addAll(cities);
notifyDataSetChanged();
}
source to share
There are two general reasons for this:
- The event, although it may look big enough, if your Spinner is too small it may not display a value, confirm this by copying the Spinner's width and height to something large. Using a custom layout for the spinner can help if this is a problem.
- You are using custom objects in your array, not simple strings or numbers that can be converted to strings. In this case, use your own class
class MyAdapter extends BaseAdapter implements SpinnerAdapter { }
.
source to share