Change your drawable to look something like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background_selected" android:state_enabled="true"
android:state_pressed="true"/>
<item android:drawable="@drawable/background_selected" android:state_enabled="true"
android:state_focused="true"/>
<item android:drawable="@drawable/background_selected" android:state_enabled="true"
android:state_selected="true"/>
<item android:drawable="@drawable/background_selected" android:state_active="true"
android:state_enabled="true"/>
<item android:drawable="@drawable/background_selectable" android:state_pressed="false"/>
<item android:drawable="@drawable/background_selectable" android:state_focused="false"/>
<item android:drawable="@drawable/background_selectable" android:state_selected="false"/>
<item android:drawable="@drawable/background_selectable" android:state_active="false"/>
</selector>
Then you set your row to tablerow.setSelected(true)
. When another row is selected, set the previous selected row to tablerow.setSelected(false)
and the newly selected row to true
I use this in one of my ListViews
and it works.
Hope this helps