我已经定义了一个任务,它只是一个复选框和一个文本。复选框在列表更新时取消选中 - Android
我也有一个显示正确的任务ListView。
问题是,当我滚动列表或当我尝试向我的列表中添加新元素时,所有复选框均取消选中,但文本保持不变。
下面是我在TaskAdapter有getView:
public View getView(int position, View convertView, ViewGroup parent) {
Task task = getItem(position);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(layoutID, parent, false);
TextView textView = (TextView) convertView.findViewById(R.id.description);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.box);
textView.setText(task.getDescription());
checkBox.setActivated(task.getBox());
return convertView;
}
在此先感谢您的帮助:d
使用checkBox.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){ @Override 公共无效onCheckedChanged(CompoundButton buttonView,布尔器isChecked){ task.setBox(器isChecked); } }); – asim
@asim。你忘了告诉OP如何确定所点击项目的使用“任务”。因为他需要一个“位置”。 – greenapps
@asim非常感谢,当我用它来改变列表中的值时,它很有用 – streiter