views:

51

answers:

2

Hi,

I have created a ListView and applied a selector to it as follows

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<item android:state_pressed="true"
    android:drawable="@drawable/my_btn_pressed" />         
<item android:state_focused="true"
    android:drawable="@drawable/my_btn_focussed" /> 
<item android:drawable="@drawable/my_btn_normal" />      
</selector>

When focussed or pressed, the background of the ListView item comes as specified in the selector. But the default background is never applied, can you tell me what is wrong?

By the way, this is the customised row xml I've used:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    android:textColor="#FFFFFF"
    android:textStyle="bold"
    android:textSize="20sp" >
</TextView>

Thanks, Kiki

A: 

Try using this code:

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
   <item android:state_pressed="true" android:state_focused="false" android:drawable="@drawable/my_btn_pressed" />         
   <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/my_btn_focussed" /> 
   <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/my_btn_normal" />      
</selector>
Martyn
Nope, this doesnt work. In default case, it is still showing no background. When focussed, the correct background(my_btn_focussed) appears. When pressed, the wrong background appears with this selector, i.e when pressed, my_btn_normal appears instead of my_btn_pressed. Now, this has totally confused me!
kiki
+1  A: 

The solution was presented as an answer to this question.

codelark
Yes, thank you CodeLark! I had found it confusing earlier. Anyways, referring your link, I got the default background for ListView to work by simply adding android:background="@drawable/my_btn_normal" in my custom row xml.
kiki