Reputation: 2684
I have a ListView being created in code like this:
ListView lv = new ListView(this);
lv.setId(GENERALLISTVIEWID);
lv.setBackgroundColor(0x333333);
lv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setDivider(null);
lv.setDividerHeight(0);
lv.setSelector(R.drawable.mainselector);
And in my mainselector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/orange" android:state_pressed="true"/>
<item android:drawable="@color/white" android:state_selected="true"/>
</selector>
The problem is, when I select the row, the entire listview underneath the cells lights up orange. Why is not just the single row turning orange?
Upvotes: 1
Views: 1481
Reputation: 2684
Okay I have solved the issue, I was making the mistake of applying the resource to my entire ListView instead of to my ListView row.
Now it is quite obvious. I have applied mainselector as the background to my ListView cell.xml instead.
Upvotes: 2