2013-12-16 94 views
1

我想将选择器应用到我的列表视图,它是一个自定义列表视图,我尝试了很多选项,但没有任何工作。任何帮助将不胜感激。我附上我的代码。由于提前Android:ListView选择器工作不正常

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> 

黄色背景效果有效地进行,但蓝效果不发生,请帮助 谢谢提前

回答

18

S将此选择器作为每行的背景而不是listview。

+0

yup..it默认项<item android:drawable="@drawable/your_default_background_for_row_item" />奋力...非常感谢 – Rohan

+0

,我有他们的孩子被扩展所有time.all我想要做的是另一种可扩展列表视图中,选择添加给他的孩子,只要他们被点击,就像我们在正常列表视图中一样。有可能 – Rohan

+0

同样的事情会起作用。请不要将此选择器设置为标题布局的背景。 –

0

您的ListView将使用自定义布局作为行项目。 因此,请尝试将该布局的背景设置为android:background="@drawable/selector_listview"。 同时一定要在你的selector_listview.xml

+0

y ...我做了同样的,因为它是由Mr.Vipul建议,它的工作,谢谢prashant – Rohan

+0

我有可扩展列表视图的另一个问题,其子节点都是全部展开的。所有我想要做的就是,只要点击它们,将选择器添加到它的子节点,就像我们在普通列表视图中一样。 – Rohan