我試圖根據不同的狀態更改特定行上的顏色。這是我目前的代碼。更改ArrayAdapter ListView中的特定行Android
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
if (row==null) {
LayoutInflater inflater=getLayoutInflater();
row=inflater.inflate(R.layout.doit, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.mess);
label.setText(ArrayAdapter.getItem(position));
switch(mState){
case STATE1:
label.setTextColor(Color.WHITE);
break;
case STATE2:
label.setTextColor(Color.BLACK);
break;
case STATE3:
label.setTextColor(Color.YELLOW);
break;
}
return(row);
}
}
代碼還挺works..but它改變了所有行。有任何想法嗎?
好吧,如果你想改變一個特定的行,你必須有一種方法來識別它。通過適配器中的對象的id或屬性,或者如果您知道它的位置......您是否明白我的意思? – Sephy 2010-07-21 14:59:58
我和你有同樣的問題,今天早些時候設法解決它。看看我的問題和答案[這裏](http://stackoverflow.com/questions/4134875/android-listactivity-row-color-based-on-object-state/4148745#4148745)。 – Holm 2010-11-10 20:52:20