I have a list view. In that list view, I have to grey out and disable some items, and enable the rest list items with seperate color. How to do this?
You should write a custom adapter extending BaseAdapter for your ListView. To disable certain items, you have to override the "boolean isEnabled(int position)" in this adapter, and return false for every position you'd like to be disabled.
As for changing the background color for certain list elements: you could store the background color value in the data structure you're displaying. In your custom adapter's 'getView()' method, you should check this color value for the current element, and return a View with the correct background color set.
Or you could just call 'getChildAt()' on the ListView, getting back the View object for the desired element in the list, and change it's background color. I think I'd rather use the previous solution.
Remember to call 'notifyDataSetChanged()' on your ListView's adapter after you make changes like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With