基本上,我有一个错误,我的 ListView 的一些 subview 会显示为选中状态,而实际上它们并未选中。例如,如果我输入 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);
}
}
}
最佳答案
记住:在 ListView
中,您在任何 subview 中设置或更改的任何内容都必须在每次显示时进行设置;您在提供的代码中所做的只是最初设置它。这意味着您的适配器还必须根据需要setBackgroundColor
,例如在bindView()
中。否则,当 View 被回收时,它将保留以前的背景颜色,并且在没有被选中时显示为选中状态。
关于java - ListView - CHOICE_MODE_MULTIPLE_MODAL - 正在选择随机项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8686668/