I am using this code, but it just does nothing:
Added to my listview:
android:listSelector="@drawable/list_selector"
Then xml files in drawable to control the diferent states
@drawable/list_selector
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/>
</selector>
@drawable/list_item_bg_normal
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:angle="90" />
</shape>
@drawable/list_item_bg_pressed
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:angle="90" />
</shape>
In the Activity:
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
view.setSelected(true);