Disabling and deleting list items

I have a list. In this view of the list, I need to cross out and turn off some elements and turn on the remaining list elements with a separate color. How to do it?

+5
source share
1 answer

You must write a custom adapter that extends the BaseAdapter for your ListView. To disable certain elements, you need to override "boolean isEnabled (int position)" in this adapter and return false for each position that you want to disable.

As for changing the background color for certain list items: you can save the background color value in the displayed data structure. In the getView () method of your custom adapter, you must check this color value for the current element and return the view with the correct background color.

Or you can simply call 'getChildAt ()' on the ListView, return the View object for the desired item in the list, and change its background color. I think I would rather use the previous solution.

Remember to call "notifyDataSetChanged ()" in your ListView adapter after making such changes.

+5
source

All Articles