2013-10-15 2 views
0

Привет, друзья, я пробовал много разных способов выделить свой список, но ничего не работает для меня. Я хочу выделить свой профиль, когда я нажимаю на него, а затем открываю новое действие.Onclick выделить строку списка не работает

вот мой XML-файл list_selector.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- Selector style for listrow --> 
<item 
android:state_selected="false" 
    android:state_pressed="false" 
    android:drawable="@drawable/gradient_bg" /> 
<item android:state_pressed="true" 
    android:drawable="@drawable/gradient_bg_hover" /> 
<item android:state_selected="true" 
android:state_pressed="false" 
    android:drawable="@drawable/gradient_bg_hover" /> 
</selector> 

вот мой gradient_bg_hover.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <!-- Gradient BgColor for listrow Selected --> 
    <gradient 
     android:startColor="#18d7e5" 
     android:centerColor="#16cedb" 
     android:endColor="#09adb9" 
     android:angle="270" /> 
</shape> 

И gradient_bg.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <!-- Gradient Bg for listrow --> 
    <gradient 
     android:startColor="#f1f1f2" 
     android:centerColor="#e7e7e8" 
     android:endColor="#cfcfcf" 
     android:angle="270" /> 
</shape> 

и моего _activity_setup.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#b5b5b5" 
     android:dividerHeight="1dp" 
     android:listSelector="@drawable/list_selector" /> 

</LinearLayout> 

помочь мне

ответ

0

Просто удалите список-селектор из вашего ListView, а вместо этого установить фон для вашего зрения пункта:

Вашего ListView:

<ListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#b5b5b5" 
     android:dividerHeight="1dp" 
     android:listSelector="@null" /> 

Ваш пункт (например):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/list_selector" > 
</LinearLayout> 

Надеюсь, это поможет.

+0

Эй, это не работает для меня! Может быть, я также вызываю onClickListener(). это проблема, почему она не выделяется? – AJay

Смежные вопросы