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();
}

      

+3


source to share


2 answers


I had a similar problem with ArrayAdapter

. I just changed it to BaseAdapter

and it works. I don't know what the reason is, but it's somewhere in the implementation ArrayAdapter

.



+2


source


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 { }

    .
+2


source







All Articles