3

PROBLEM

My problem is that after changing data in my SpinnerArrayAdapter my Spinner does not react to item clicks on dropDownList. However after orientation change occurs everything is working fine(?!). EDIT: I noticed it does catch the item clicks but not representing/showing it on Spinner. Because after orientation change the selected item appears on Spinner

CONSTRUCTION

I have AutoCompleteTextView(ACTV) that's connected to AutoCompleteAdapter implementing Filterable. After entering some data into ACTV the result is passed to SpinnerArrayAdapter that is connected to Spinner.

There is a customListener set on AutoCompleteAdapter that is connected to SpinnerArrayAdapter and responsible for passing data between them.

Reason behind such construction is that user can have a 2-step choice. One on drop-down when choosing the data from ACTV and second one in case he change his mind. So you can put POSTCODE in the ACTV select province that's connected to and change province when you miss-clicked/changed mind without forcing to enter POSTCODE again.

CODE

This is the part that is responsible for data change inside SpinnerArrayAdapter.

@Override
public void setCitiesFromPostcode(ArrayList<String> cities) {
    this.clear();
    this.addAll(cities);
    notifyDataSetChanged();
}
JakubW
  • 1,101
  • 1
  • 20
  • 37

2 Answers2

3

I had a similar problem with ArrayAdapter. I just changed it to BaseAdapter and it works. Don't really know what the reason is, but it's somewhere in the implementation of ArrayAdapter.

Michał Klimczak
  • 12,674
  • 8
  • 66
  • 99
2

Two common causes for this:

  1. Event though it may look big enough, if your Spinner is too small it may not be able to display the value, confirm this by hardcoding the Spinner width and height to something large. Using a custom spinner item layout may help if this is the problem.
  2. You're using custom objects in your array, not simple Strings or numbers that can be converted to strings. Use a custom class MyAdapter extends BaseAdapter implements SpinnerAdapter { } class in this case.
richardleggett
  • 424
  • 4
  • 7