CursorAdapter 内的 mcheckBox.setOnCheckedChangeListener
我有一个使用自定义 CursorAdapter 填充的 ListView。在 BindView 中,我有以下代码:
CheckBox mCheckBox = (CheckBox) view.findViewById(R.id.list_done);
mCheckBox.setChecked(isDone);
mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
AW.getDB().updateTask(c.getInt(c.getColumnIndex(ToDoDBAdapter.KEY_ID)), isChecked);
TD.displayTasks();
}
});
但是,当设置列表中的一个复选框时,运行的代码似乎适用于列表中最后一项的光标位置。因此,在 4 个项目的列表中,
c.getInt(c.getColumnIndex(ToDoDBAdapter.KEY_ID))
应该分别返回 1、2、3、4,选中 4 个框中的任何一个都会给出值 4。有人知道这是为什么吗?
换句话说,列表中每个 CheckBox 的 onCheckedChangedListener 都是相同的。
I have a ListView that is populated using a custom CursorAdapter. Within BindView, I have the following code:
CheckBox mCheckBox = (CheckBox) view.findViewById(R.id.list_done);
mCheckBox.setChecked(isDone);
mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
AW.getDB().updateTask(c.getInt(c.getColumnIndex(ToDoDBAdapter.KEY_ID)), isChecked);
TD.displayTasks();
}
});
However, when one of the checkboxes in the list is set, it seems as though the code that runs applies to the cursor's position as of the last item in the list. Thus, in a list of 4 items where
c.getInt(c.getColumnIndex(ToDoDBAdapter.KEY_ID))
should return 1, 2, 3, 4 respectively, checking either of the 4 boxes gives the value 4. Anyone know why this is?
In other words, the onCheckedChangedListener is the same for every CheckBox in the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论