What I want to achieve:
- A list item is highlighted when the user is pressing it
- When the user stops pressing it, the list item:
- remains highlighted, if it was unselected before the pressing
- loses the highlight, if it was selected before the pressing
- Long clicks behave the same way as the user stopping the pressing (changing the background of the item depending on its previous state)
- Scrolling the list, without pressing any specific item, should not highlight any item
Details:
- For what I read, I think that behaviour could be achieved using list selectors and the state android:state_activated, but this state was introduced in API level 11. The solution I am looking for has to work in API level 10
- I think that solutions relying on click (onItemClick, onClick...) will not work, because the click is triggered after the user stops the pressing, not when he starts it (like the pressed state does). Changing the highlight of an item using android:state_pressed is not persistent (it will change back after the press is finished) and changing it in android:state_pressed and making it persistent on click will produce a flicker
- A good example of app that achieves that in API level 10 is Tasks. Just click or long click on items in the list to see the desired behaviour
So, anybody has already solved that? Any idea on how the Tasks app does it?