I have two spinners that I want to "bind" to each other in a mutually exclusive sense: if you select an element in one, this element text will turn red and appear at the top, and the other will return to display the initial ("title") selection (if earlier another item was selected) and its text becomes white.
All this is done through onItemSelected listeners:
sectionSpin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View arg1, int position, long arg3) { issueSpin.setSelection(0); ((TextView) issueSpin.getChildAt(0)).setTextColor(Color.parseColor("#FFFFFF")); ((TextView) arg1).setTextColor(Color.parseColor("#E3170D")); ....
and vice versa for the "spinner" question. My problem is that if I switch from one counter to another and I select the top item, onItemSelectedListener is not registered, because the selected item is already selected.
I was told that this is impossible. Or rather, I was told that it is not possible for the onItemSelected listener to fire an element that is already selected. Although I understand that this is technically true, this problem seems relatively simple, and I'm sure there should be a workaround to get the desired effect.
I have a few questions regarding some that I'm thinking about:
- Is there a way to set all the elements in the counter as unselected, while showing one of them?
- Is it possible to use a different type of event (e.g. setOnTouchListener, setOnClickListener, etc.), presumably on the top element, in combination with
onItemSelectedListener ? - If I use a different type of event on my own, perhaps in Views that are inflated in the counters themselves, without
onItemSelectedListener ? - Can you help me find a better strategy than the ones mentioned in the paragraphs above?
source share