我正在尝试根据不同的状态更改特定行的颜色。这是我目前的代码。
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);
}
该代码有点工作..但它改变了所有的行。有什么想法吗?
最佳答案
因此 android 每次都会重复使用 View ,这就是为什么您会看到它影响所有行。您需要做的是为每种情况明确设置颜色。也许向您的 switch 语句添加一个“默认”案例,以便将其设置为您在布局中的默认值?
关于android - 更改 ArrayAdapter ListView Android 中的特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3300565/