I have a ListFragment whose ListView is set to ListView.CHOICE_MODE_SINGLE. The adapter returns a custom row layout and I'm setting the background of each row layout to a selector.
But I can't seem to define the selector so that on a long-press, the row stays highlighted, but on a normal press, it just highlights briefly.
Here is my selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@color/light_blue" />
<item android:drawable="@android:color/transparent" />
</selector>
The row stays highlighted on long-press, but a normal press also makes the row stay highlighted. I've tried using various combinations of attributes in each item but can't get it right.
Clarification: I would still like it so that when another row is pressed, the previously long-pressed (and highlighted) row becomes un-highlighted. And the above selector does do that.
If you want to use states, look at the default states android defines to make sure there isn't one already. If android doesn't have a state that suits your needs, take a look at defining custom states here How to add a custom button state
If you don't want to do that you can always add selections to a list and change backgrounds in
getView
as my comment hints.