我已经在可扩展列表视图中设置了备用组标题的两种颜色。但是,当我多次点击展开或折叠颜色变化到任何组行。可扩展列表视图组标题颜色变化
这里是我的代码,
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
if(groupPosition % 2 == 1) {
convertView.setBackgroundColor(Color.parseColor("#3C3C3C"));
}else {
convertView.setBackgroundColor(Color.parseColor("#000000"));
}
}
这是滚动列表后发生。我也试过这一个
private int[] colors = new int[] { Color.parseColor("#000000"), Color.parseColor("#3C3C3C") };
int colorPos = groupPosition % colors.length;
convertView.setBackgroundColor(colors[colorPos]);
我已经尝试this.but不工作。颜色发生变化,但是在颜色转换后,颜色会移动到任何一行。 –
首先检查:if(convertView == null){ \t \t \t convertView = inflater.inflate(R.layout.listrow_group,null); \t \t}然后在If条件的旁边设置代码。 –
在我的代码::如果(convertView == NULL){ LayoutInflater infalInflater =(LayoutInflater)this._context \t \t \t \t \t .getSystemService(Context.LAYOUT_INFLATER_SERVICE); \t \t \t convertView = infalInflater.inflate(R.layout.list_item,null); \t \t} –