Rohan
Rohan

Reputation: 188

Android:ListView Selector not working properly

I am trying to apply selector to my list view ,it is a custom list view, I tried so many options but nothing worked. Any help will be greatly appreciated. I am attaching my code. Thanks in Advance

selector_listview.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@drawable/faintblue" />
    <item android:state_focused="true" android:drawable="@drawable/yellow" />

</selector>

layout_listview.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="match_parent"
    android:background="#ffffff" >

    <ListView
        android:id="@+id/lvChatList"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/rlHeader"
        android:background="@drawable/selector_expandable_listview"
        android:listSelector="@drawable/selector_expandable_listview" >

    </ListView>

    <TextView
        android:id="@+id/tvNoChats"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="No Chats"
        android:visibility="gone" />

</RelativeLayout>

yellow background effect takes place effectively but blue effect is not taking place,Please help Thanks in advance

Upvotes: 3

Views: 5765

Answers (2)

Prashant Thakkar
Prashant Thakkar

Reputation: 1403

Your ListView will be using Custom Layout for row item. So try to set background for that layout to android:background="@drawable/selector_listview". Also make sure to have default item <item android:drawable="@drawable/your_default_background_for_row_item" /> in your selector_listview.xml

Upvotes: 0

vipul mittal
vipul mittal

Reputation: 17401

Set this selector as background of each row instead of listview.

Upvotes: 20

Related Questions