基本上,我有一个错误,我的一些列表视图的孩子会出现被选中,而实际上他们不是。例如,如果我输入ActionMode
并仅选择第一个孩子,则会出现其他几个孩子,好像我已经选中了他们,但实际上并未选中。为什么会这样?
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
final int checkedCount = lv.getCheckedItemCount();
mSelectedConvCount.setText(Integer.toString(checkedCount));
if (checked) {
lv.getChildAt(position).setBackgroundColor(
Color.BLUE);
} else {
lv.getChildAt(position).setBackgroundColor(
Color.TRANSPARENT);
}
}
}
答案 0 :(得分:1)
请记住:在ListView
中,每次显示时,您在任何子视图中设置或更改的内容都必须设置;你在提供的代码中所做的就是最初设置它。这意味着您的适配器也必须setBackgroundColor
适当,例如在bindView()
。否则,当视图被回收时,它将保留以前的背景颜色,并在不显示时显示为选中。