Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabling and greying out list items

Tags:

android

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?

like image 391
mdv Avatar asked Oct 08 '10 06:10

mdv


1 Answers

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.

like image 150
Zsombor Erdődy-Nagy Avatar answered Sep 30 '22 04:09

Zsombor Erdődy-Nagy