:
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)をチェックアウトする必要があります。また、Google I/O 2009と2010のListViewsで、まったく不可能なRomain Guyのプレゼンテーションをチェックしてみてください。心の痛み、混乱、痛み、パフォーマンス調整の時間を節約できます。