I'm writing a program which uses a Listview (with a custom adapter) and I want to disable some items in the listview. I'm doing so by using this code (so far so good):
@Override
public boolean isEnabled(int position) {
if ((position == 2 || position == 3) && mBool1) {
return false;
}
return true;
}
However, this doesn't provide any visual cues... only the fact that after you set the boolean mBool1, you can't click on list items at positions 2 and 3, but the background stays the same. How can I change the background color for disabled listview items to be different from the enabled ones? I'm trying to use a selector, but I can't find the right combination.
And it shouldn't. All the visual state is calculated in getView
(or bindView
, depends on adapter type you are using). So you should do something like:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the view
if(isEnabled(position)) {
view.setBackground(...);
} else {
view.setBackground(...);
}
}