Gerardo
Gerardo

Reputation: 5830

Android Selector Problem

i have a listview with a custom item_row.xml. I've defined a selector in this way:

<?xml version="1.0" encoding="utf-8"?>

<item
    android:state_pressed="false"
    android:drawable="@drawable/list_bg" >
</item>
<item 
    android:state_pressed="true"
    android:drawable="@drawable/header_bg" >
</item>
<item
    android:state_focused="false"
    android:drawable="@drawable/list_bg" >
</item>
<item
    android:state_focused="true"
    android:drawable="@drawable/header_bg">
</item>

and then put into item_row.xml in this way:

    <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="70dip"
  android:orientation="vertical"
  android:background="@drawable/list_selector"> 

I want 2 things:

Any idea? I try to set also into the ListView android:listSelector="@drawable/list_selector" but it doesn't work neither.

Thanks

Upvotes: 0

Views: 2551

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006674

You should model your StateListDrawable after the one used by Android itself for ListView selectors. You can find this in $ANDROID_HOME/platforms/$VERSION/data/res/drawable/list_selector_background.xml, where $ANDROID_HOME is where your Android SDK is installed and $VERSION is some Android version (e.g., android-2.1). Then, apply the list selector via android:listSelector in the ListView in your layout XML.

Upvotes: 1

Related Questions