Click an item in the horizontal ListView

I created a horizontal ListView as described at http://www.dev-smart.com/archives/34 .

Everything works fine, the only problem is that the effect we get when we click on an item (changing the color of the clicked cell) is not present in the custom horizontal list.

Is there any way to overcome this problem.

+3


source to share


1 answer


In my application, I added the following files to the drop down folder to change the color of the list item after 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 it helps :)

+1


source







All Articles