1

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?

4

1 回答 1

2

好的,我已经解决了这个问题,我错误地将资源应用到我的整个 ListView 而不是我的 ListView 行。

现在已经很明显了。我已将 mainselector 作为背景应用到我的 ListView cell.xml 中。

于 2012-08-01T15:49:01.420 回答