我试图根据不同的状态更改特定行上的颜色.这是我目前的代码.
@H_301_6@ 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语句中添加“默认”大小写,以便将其设置为布局中默认的值?