I'm using SherlockListFragment to show list items, and I want to set the background of list item highlighted when it is checked. But after I did all the things below, the list item background still remain unchanged when set checked (but it changes when clicked). Why?
The list selector => drawable/list_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/transparent" />
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/list_selector_background_dark" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/list_selector_background_dark" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_dark" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_dark" />
<item android:state_checked="true"
android:drawable="@drawable/list_selector_background_dark" />
</selector>
The list item layout => layout/list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:background="@drawable/list_selector_dark">
......
</RelativeLayout>
The fragment layout => layout/fragment_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_gravity="start"
android:scrollbars="none"
android:fastScrollEnabled="true"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_selector_dark" />
<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_entry" />
</LinearLayout>