0

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> 
2
  • What @android:color/transparent, @drawable/list_selector_focused and @drawable/list_selector_pressed contains? Commented Jul 24, 2012 at 7:58
  • @Tobias Moe Thorstensen Try two things. First: set your listiew clickable and longClickable atributes to true and report. Second: Try registering yout listview for contextmenu via registerForContextMenu(). If you have to implement dummy listener. Report your findings. Commented Sep 18, 2013 at 11:54

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

What items? The items in the list? Where should I specify this?
In the XML of these item, under your layout folder. Or, are you using a resource provided by the Android platform? I am not sure if this is the fix to your problem, but it might be.
Yes, and it has no background color, so the bug has to be anywhere else. Your item views are focusable, aren't they?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.