mcheckBox.setOnCheckedChangeListener within CursorAdapter

大兔子大兔子 提交于 2020-01-15 05:10:08

问题


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.

来源:https://stackoverflow.com/questions/8549386/mcheckbox-setoncheckedchangelistener-within-cursoradapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!