On the default ListViews if you long press on an item the background fades from dark blue to light blue(on Galaxy Tab. Its orange to light orange on some other devices) during the time it takes to register a LongClick. I am assuming this is done somehow with a selector but thus far I've only seen how to use selectors for state:selected, state:focused, and state:pressed.
This page doesn't seem to show anything about a LongClick state so perhaps my assumption that this is accomplished with a selector is incorrect?
Can anyone fill me in on how the default ListView gets this effect and how I can apply it to other views?
http://developer.android.com/guide/topics/ui/menus.html#context-menu
So its an animation that is used. I believe it uses the View's own default On...() methods to display it. You may need to worry about giving it clickable="true" or longClickable="true" attributes.
In addition to your OnTouchListener, you can use a Runnable to revert back the background to it's original state so that you don't need to explicitly do it in the OnLongClick handler.
where ResetBG is:
So it turned out to be a little bit more difficult than I had thought but I have it working almost correctly now.
Here is the OnTouchListener I ended up using:
I also used an OnLongClickListener inside this I set the background back to the normal one.
Here is the Transition XML:
You may be asking whats with the bubblelight1? More on that in a moment.
Here is the getView() Method I use inside my adapter to return the views that get displayed in the List:
v.setOnTouchListener(listOnTouchListener); and v.setOnLongClickListener(listOnLongClickListener); are the lines that set up the view with the Listeners that I've shown above.
Now about the bubblelight1. bubblelight and bubbledark are the nine patch images I am using when I tried this the first time whenever the transition started instead of the background transitioning from bubblelight to bubbledark, bubblelight would grow bigger and bubbledark would appear inside of bubblelight. So I had a big bubble that was light, a smaller bubble that was dark, then the text inside that. To fix this issue I made a copy of bubblelight and made the bottom and right edges of the ninepatch completely filled in. I just had to do the first image in the transition though, not the second. If I did the second image that way then my text would jump out of the bubble and some it would get shown over the top and along the sides of the bubble. I am not entirely sure why this was happening, or why this fix happened to work. But It does the job for now.