0

We have created custom listview by using the Base adapter. List view contains Text View and Edit Text. My requirement is that when focus is coming on the row only that row has to highlights and when focus changes new focus row has to highlights and Old row becomes the normal. I have tried by using set background color but when I set Color to one row and goes to another row previous row has to change normal and new focus row becomes color but it is not working properly.

mayur rahatekar
  • 4,410
  • 12
  • 37
  • 51

2 Answers2

3

just define a selector.xml file with:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="@color/black" />
    <item android:state_pressed="true" android:color="@color/red" />
    <item android:color="@color/white" />
</selector>

And apply it inside the <ListView> by using android:listSelector="@drawable/selector.xml"

Useful Tip:

Whenever you want to change the color for a particular view on different state like pressed/focused/selected then just define a selector.xml file and then apply it using either android:background (in button) or android:listSelector (in listview).

Enjoy!

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • I have tried the above solution it's working. But my requirement is little different. In above solution when user clicks the text view highlight but it's focus goes.... But I want when user clicks on one row then then focus remain till we pressed on other focus – mayur rahatekar Nov 04 '11 at 09:54
0

You need to write one Selector XML to Specify the Background color/drawable of Row when any event(pressed/focused) occurs like THIS EXAMPLE

Other Same Kind of Question I think Question1,Question2

Community
  • 1
  • 1
MKJParekh
  • 34,073
  • 11
  • 87
  • 98