Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android Custom Listview Background Focus State not working

Tags:

android

I am trying to create custom background selector for my ExpandableListView. It works fine for all states other than focused. I am unable to identify which row is currently focused. Here is the code:

im_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true"
        android:drawable="@drawable/list_selector_background_focus" />
    <item android:state_pressed="true"
        android:drawable="@drawable/list_selector_background_pressed" />

    <item 
        android:drawable="@drawable/list_bg" />

</selector>

my listview in the layout file

<ExpandableListView android:id="@+id/android:list"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:scrollbars="horizontal"
              android:layout_below="@id/top_bar"
              android:layout_marginBottom="45px"
              android:divider="#00000000"
              android:cacheColorHint="#00000000"
              android:listSelector="@layout/im_selector"
              android:focusable="true"              
            />
like image 701
Adnan Avatar asked Jun 18 '10 17:06

Adnan


1 Answers

When you use touch mode with listview, 'selected' attribute changes rather than 'focused'. That is why, for listviews you should add line like this one in your selector:

<item 
    android:state_selected="true" android:drawable="@drawable/list_selector_background_focus" />
like image 87
bart Avatar answered Sep 22 '22 01:09

bart