1

I needed to use custom title bar so I changed the manifest and created my custom theme. Till here every thing was fine, but same activity was having a list view, so I used custom list view and changed accordingly. Every thing went fine, But on click of any item in list view, item was not getting highlighted. I went through various links but not found the solution. I have gone through this link which has similar problem but solution is not working in my case. If any body could help.

My attempt: My list_bg.xml is

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item 
    android:drawable="@color/grey" />
<item android:state_pressed="true" 
    android:drawable="@color/blue" />
<item android:state_selected="true"
    android:state_pressed="false" 
    android:drawable="@color/blue" />
</selector>

I have added the above code in color folder and gave the reference as android:background="@color/list_bg" in list view item xml.

Any help will be appreciated, thanks in advance

Community
  • 1
  • 1
Android
  • 3,828
  • 9
  • 46
  • 79

2 Answers2

0

Put

<item 
android:drawable="@color/grey" />

at the end of your XML. The state list is traversed top to bottom and the first item that matches the current state is used

207
  • 3,784
  • 2
  • 25
  • 22
  • thanks for reply sir but no, its not help full. still its like static list – Android Apr 17 '12 at 12:10
  • What do you mean by "static list"? Does you list get highlighted by "standard" `ListView` style? – 207 Apr 17 '12 at 12:28
  • no, its not getting highlight, that's my problem and question. Its like onItemClickListner is not working – Android Apr 17 '12 at 12:30
  • Are your items enabled? Do you override `isEnabled()` or `areAllItemsEnabled()` and returning `false`? – 207 Apr 17 '12 at 12:31
  • no, I am not overriding such functions. I just created a list view and custom theme. and my list view was not showing default behaviour – Android Apr 17 '12 at 12:35
  • it seems like attribute from list_bg is in background because default color is not shown in front list but it shown somewhat faded at background on right portion where list is ending – Android Apr 17 '12 at 12:41
  • Try adding `android:listSelector="@android:color/transparent"` to your `ListView` XML definition – 207 Apr 17 '12 at 12:43
  • No still the same result, I mean no result. – Android Apr 17 '12 at 12:45
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10175/discussion-between-207-and-black-devil) – 207 Apr 17 '12 at 12:49
0

android:listSelector="#000000"

use this attribute in listview.

Himanshu Mittal
  • 225
  • 1
  • 5