Friday, 15 July 2011

android - My ListView background selector won't highlight the selected row -



android - My ListView background selector won't highlight the selected row -

i used this question guide, when click row doesn't remain highlighted. wrong code?

score_list.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <listview android:id="@+id/score_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@+id/keyboard" android:listselector="@drawable/selector" android:choicemode="singlechoice" android:divider="#cccccc" android:dividerheight="1dp" android:paddingleft="15dp" android:paddingright="15dp" /> ... </relativelayout>

drawable/selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@color/highlight"/> <item android:state_pressed="true" android:drawable="@color/highlight"/> </selector>

score_row_item.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scorerowlayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:background="@drawable/row_selector" > ... </linearlayout>

drawable/row_selector.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@color/highlight" /> <item android:state_activated="true" android:drawable="@color/highlight" /> <item android:drawable="@color/transparent" /> </selector>

this code works properly.

try utilize state_activated row_selector.

android listview selector

No comments:

Post a Comment