views:

365

answers:

1

Hi there.

I have a list of checked items. I used the simple_list_item_multiple_choice.xml layout from android from the list.

My requirement for this list is: - When I check the checkbox of an item, the background color of that row will change. (For e.g. black background to green) - Then when I uncheck the checkbox, the background color of that row will back to original (green to black)

Is there any way to implement that? What I want here is different from the orange color when you scroll the list, which is made by default for the list in Android.

Thank you very much for your help.

+1  A: 

This is not a UI pattern in use on Android. Android apps frequently come up short in comparison to iPhone apps because iPhone apps follow a consistent UI pattern and Android apps are all over the map. Please tell whoever wrote your requirements to obtain and use an Android device for a month before coming up with ideas like this. And I urge you not to implement this "feature".

That being said, you would need to create a custom StateListDrawable, perhaps through drawable XML, for your list rows. That XML would need to retain the existing orange highlight used when the row is selected, but use your green background when the row is in the normal state. Then, when the checkbox is checked, you would need to arrange to change the background of that row to the custom StateListDrawable.

You may want to hold onto the original background (e.g., via setTag() on the row) to swap it back in, since you may not have ready access to whatever resource is being used for the original background. Or, create two StateListDrawables, one that you use for the normal case and one for the checked case.

CommonsWare