0

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<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

kiki
  • 13,627
  • 17
  • 49
  • 62

3 Answers3

1

The solution was presented as an answer to this question.

Community
  • 1
  • 1
codelark
  • 12,254
  • 1
  • 45
  • 49
  • 1
    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 Sep 29 '10 at 11:41
0

In your Textview, you should try to change this...

android:background="@drawable/<b>my_btn_normal</b>"

to this...

android:background="@drawable/<b>your selector's name</b>"
wattostudios
  • 8,666
  • 13
  • 43
  • 57
0

Try using this code:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <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
  • 16,432
  • 24
  • 71
  • 104
  • 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 Sep 29 '10 at 05:28