您需要将Adapter(或其子类型之一)子类化,并在
getView
方法:
TextView row;
// Recycle an already-inflated view if possible
if (convertView == null) {
row = (TextView) View.inflate(android.R.layout.simple_list_item_1, getContext());
} else {
row = (TextView) convertView;
}
SomeModel myItem = getItem(pos);
if (getItem(pos).displayFunky()) { //or whatever object condition you want to check
row.setTextColor(Color.RED)
} else {
row.setTextColor(Color.GREEN)
}
row.setText(myItem.getDisplayText());
return row;
您也可以有一个具有多个视图类型的自定义适配器,但这是一个足够简单的情况,我可能不会费心。另请参见
this SO post
one from NPR
,以及适配器中更复杂的多个视图
tutorial
. 你也应该在谷歌I/O中明确地查看LoMist-Ge的ListVIEW演示文稿。
2009
和
2010