tags:

views:

34

answers:

2

When I change the background color of a list item it no longer flashes green when selected. Is there a way to retain this default behavior when the background is changed?

A: 

u can set the background resource for the view with

setBackgroundResource(android.R.drawable.menuitem_background);

and get the desired effect

the100rabh
+1  A: 

The "green flash" is part of the background. By replacing the background (presumably, with a simple color), you eliminated the flash.

First, consider whether you should be changing the background of a list item. For example, if you are doing all of the list items this way, perhaps the ListView should have the background color.

If that does not help, you need to make the background be a StateListDrawable with the appropriate states.

CommonsWare
Your response was helpful, thank you. The background for each item in this list can be configured via an xml file brought in by http when the app starts up. I found a way to do what I want using an onTouchListner. Not sure if that's the best way.
Tom