Search code examples
androideclipselistviewstates

Android Eclipse add "Button-like state" to listview items


What is the quickest way to set your list view items so that when you click on them they flash to a different state to let the user know they clicked on it? Something like a quick image change, color change, border color, etc.


Solution

  • Here is how you create a selector for the listview using colors..

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:state_selected="false" android:state_pressed="false" 
        android:drawable="@color/grey" />
    
        <item android:state_pressed="true" android:drawable="@color/blue" />
    
        <item android:state_selected="true" android:state_pressed="false" 
        android:drawable="@color/blue" />
    
    </selector>
    

    Here is an excellent tutorial.Customizing Listview selected color