且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android CheckBox - 删除以前 setOnCheckedChangeListener

更新时间:2023-12-03 18:20:34

您可以执行以下操作:

// c is the Cursor you are getting
CheckBox mCheckBox = (CheckBox) view.findViewById(R.id.list_done);
mCheckBox.setTag(new Integer(c.getPosition());
mCheckBox.setChecked(isDone);
mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        Integer posInt = (Integer)buttonView.getTag();

        int pos = posInt.intValue();
        c.moveToPosition(pos);
            AW.getDB().updateTask(c.getInt(c.getColumnIndex(ToDoDBAdapter.KEY_ID)), isChecked);
            TD.displayTasks();
    }
});

您可以对上述代码进行很多优化.我只是说明了基本逻辑.

There are lots of optimizations you can do to above code. I just illustrated the basic logic.