3

I have created horizontal listView as described in http://www.dev-smart.com/archives/34 .

Everything works fine the only problem is that the effect we get when we click an element (color change of the clicked cell) is not there in the custom horizontal list.

Is there a way to overcome this issue

pvn
  • 2,016
  • 19
  • 33

1 Answers1

1

In my app I have added the following files to the drawable folder to change the color of the list item once it is selected:

List_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <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.xml

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

  <gradient
      android:startColor="#f1f1f2"
      android:centerColor="#e7e7e8"
      android:endColor="#cfcfcf"
      android:angle="270" />
</shape>

gradient_bg_hover.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <gradient
      android:startColor="#A6A6A6"
      android:centerColor="#757575"
      android:endColor="#4A4A4A"
      android:angle="270" />
</shape>

Hope this helps :)

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79