2014-09-28 45 views
0

我有一個listView,我不想搞清楚如何選擇只在我點擊它時選擇的行。使用此代碼,所選行將在點擊後保持下劃線,並在我選擇新行時消失。listView的行仍然在線

<ListView 
     android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/list_background" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="1dp" 
     android:listSelector="@drawable/list_selector" /> 

列表選擇:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/> 
    <item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/> 
    <item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/> 

</selector> 

是有可能實現這個功能嗎?

UPDATE

我想要實現這個功能。

enter image description here

enter image description here

與此代碼所選行好好嘗試一下做描述成截屏,這其中仍然強調。

在此先感謝。

+0

您可以發佈您的屏幕拍攝....它不清楚你所告訴的.. – 2014-09-28 09:01:50

+0

@坦尼米哈OK等一下。 – 2014-09-28 09:07:10

+0

@Tanimreja查看更新。 – 2014-09-28 09:12:08

回答

2

我認爲這對你有幫助。 在list_selector xml文件,請添加以下代碼

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

</selector> 

這個代碼工作爲我好。如果再面對任何問題發表評論。謝謝enter image description here

+0

你救了我的一天,非常感謝:) – 2014-09-28 09:58:28

+0

不客氣 – 2014-09-28 10:01:47