I have a listview (actually two) that I want to do a custom selection highlight for (where i use a custom background color, change the text color, and change the icon). So I wrote a custom SelectionListener class that implements AdapterView.OnItemSelectedListener, in the onItemSelected() method I set all the children of the adapterview to the default background and text color and default icon, then I set the selected child view to the special background color, and icon. In the onnothingselected method I set all the children to have the default background and icons. When I run my app, when I scroll through the list it works, the selected item has the right background and stuff and the others are default, but when I scroll back to the top of the list and then off the listview, the top element stays selected or highlighted. WTF? The tab I have at the top is also selected, so it appears two things are selected (the tab and first item in the list). Thanks for any help.
Here is my selectionlistener code:
Using java Syntax Highlighting
- public class OptionsSelectionListener implements AdapterView.OnItemSelectedListener
- {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
- {
- unSelectAll(parent);
- ((OptionView) view).highlight();
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- unSelectAll(parent);
- }
- public void unSelectAll(AdapterView<?> parent)
- {
- int numChildren = parent.getChildCount();
- for(int k = 0; k < numChildren; k++)
- {
- ((OptionView) parent.getChildAt(k)).unhighlight();
- }
- }
- }
Parsed in 0.049 seconds, using GeSHi 1.0.8.4



