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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.