I have a list view and an adapter that sets alternating background colors to the list items (“zebra” list style):
public View getView(final int position, View convertView, ViewGroup parent) {
int colorPos = position % colors.length;
...
convertView.setBackgroundColor(colors[colorPos]);
return convertView;
}
But now, when i select an item using scroll wheel, or when I click an item, the original colors for selecting/clicking do not override my custom backgrounds (I can see the original color below the one I set).
How can I set the original colors for these states?
I think the easiest way is to create two selectors which are used as the background resources, with transparent color in the state_selected mode:
(res/drawable/alterselector1.xml:)
(res/drawable/alterselector2.xml:)
(res/values/colors.xml:)
Then you set the backgrounds in the getView method of the adapter with the setBackgroundResource method:
Now when you select a row, your background don’t hide the original selector behind.