Tobias Moe Thorstensen
Tobias Moe Thorstensen

Reputation: 8981

List selector android

I've got two shapes like this:

List_selector_focused.xml

<gradient
    android:startColor="#f5c98c"
    android:endColor="#f7ddb8"
    android:angle="90" />

</shape>

and list_selector_pressed.xml

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

<gradient
    android:startColor="#fb9d23"
    android:endColor="#ffc579"
    android:angle="90" />

</shape>

and my list_selector.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/list_selector_pressed" />

<item
    android:state_focused="true"
    android:drawable="@drawable/list_selector_focused" />

<item
    android:drawable="@android:color/transparent" />

</selector>

And to my listview, I add the list_selector.xml

 <ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:cacheColorHint="#0A3A5C"
    android:scrollbars="none"
    android:listSelector="@drawable/list_selector">

But there is no color appearing when i press one of the items in the listview, any suggestions?

EDIT

The list I try to apply this to, is a custom list. The layout for each of the items in the list:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingTop="10dip" >

<TextView
    android:id="@+id/idNumber"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="First"
    android:textColor="#11629F"
    android:textSize="17sp"
    android:textStyle="bold" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

</LinearLayout>

<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/idNumber"
    android:layout_below="@+id/idNumber"
    android:text="Second"
    android:textSize="15sp" />
 </RelativeLayout>

Upvotes: 0

Views: 3989

Answers (1)

I&#241;igo
I&#241;igo

Reputation: 12823

Do your Items have a constant background color? If so, your selector is not going to be displayed, since this selector is set on the back of your item. Make sure your item's background is transparent when selected, in order to have your selector visible.

Upvotes: 2

Related Questions