I have gone over several SO answers now
Android listselector not visible in custom listview
ListView item background via custom selector
and even followed this to the point (currently using this approach)
http://cyrilmottier.com/2011/08/08/listview-tips-tricks-3-create-fancy-listviews/
I have even set the drawSelectorOnTop
to true
However, I cannot get the listSelector
to work. Basically, I am at my wit's end. I guess it has something to do with the way my list item is made? Here is the XML:
list_entry.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="5dp">
<ImageButton android:id="@+id/contextMenuIcon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_overflow"
android:background="@null"/>
<TextView android:id="@+id/noteTitle"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/contextMenuIcon"
android:layout_alignBottom="@id/contextMenuIcon"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:textIsSelectable="false"
android:ellipsize="end"
android:singleLine="true"
android:textSize="20sp"
android:textColor="@android:color/black"/>
<TextView android:id="@+id/noteCreationDate"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_below="@id/noteTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#808080"/>
<TextView android:id="@+id/notePrivacy"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_below="@id/contextMenuIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#808080" />
</RelativeLayout>
list_selector_pressed.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:endColor="#ffc579" android:startColor="#fb9d23" android:angle="90"></gradient>
</shape>
list_selector_focussed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:endColor="#f7ddb8" android:startColor="#f5c98c" android:angle="90"></gradient>
</shape>
list_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/list_selector_pressed" />
<item android:state_focused="true" android:drawable="@drawable/list_selector_focused" />
<item android:drawable="@android:color/transparent" />
</selector>
Please tell me how to make the list selector work!