Scope: - using overriden ArrayAdapter; - using selector; - using isEnabled for disabling items.
Aim: - disable some list items and
Hack: use getView to check disabled item logic and inflate view with another layout. isEnabled is still usefull.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row;
if (mListItem[position].isEnabled() == false) row = inflater.inflate(
R.layout.list_row_disabled, null);
else {
row = inflater.inflate(R.layout.list_row, null);
// set right extensible icon
if (mListItem[position].getType()) {
ImageView ic_arrow = (ImageView) row.findViewById(R.id.list_row_arrow);
ic_arrow.setImageResource(R.drawable.ic_arrow_right);
}
}
// set left icon
ImageView ic_item = (ImageView) row.findViewById(R.id.list_row_icon);
ic_item.setImageResource(mListItem[position].getIcon());
// blend icon if item is disabled
if (mListItem[position].isEnabled() == false)
ic_item.setColorFilter(0x99D0D0D0,Mode.SRC_ATOP); // make icons look grayer
// set title text
TextView txvTitle = (TextView) row.findViewById(R.id.list_row_title);
txvTitle.setText(mListItem[position].getTitle());
return row;
}
@Override
public boolean isEnabled(int position) {
return mListItem[position].isEnabled();
}