在ArrayAdapter的ListView的Android更改特定的行 [英] Change a specific row in a ArrayAdapter ListView Android
本文介绍了在ArrayAdapter的ListView的Android更改特定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图改变依赖于不同状态的特定行的颜色。这是code I具有的时刻。
I am trying to change the color on a specific row depending on different states. This is the code i have at the moment.
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);
}
}
在code还挺works..but它改变了所有行。任何想法?
The code kinda works..but it changes all the rows. Any ideas?
推荐答案
因此Android每个重用,这就是为什么你看到它影响所有行的时间观。你需要做的是明确设定了每种情况的颜色。这样将其设置到任何你默认布局中默认情况也许添加到您的switch语句?
so android reuses the View each time that's why you're seeing it affect all the rows. What you need to do is explicitly set the color for each case. perhaps add a 'default' case to your switch statement so that it sets it to whatever you're default is in the layout?
这篇关于在ArrayAdapter的ListView的Android更改特定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文