2016-10-25 27 views
0

我已经定义了一个任务,它只是一个复选框和一个文本。复选框在列表更新时取消选中 - 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

+0

使用checkBox.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){ @Override 公共无效onCheckedChanged(CompoundButton buttonView,布尔器isChecked){ task.setBox(器isChecked); } }); – asim

+0

@asim。你忘了告诉OP如何确定所点击项目的使用“任务”。因为他需要一个“位置”。 – greenapps

+0

@asim非常感谢,当我用它来改变列表中的值时,它很有用 – streiter

回答

2

task.getBox()函数返回false。那就是问题所在。请检查该区域。

+0

即使我编写了setActivated(true),我的框仍然未被选中 – streiter

0

checkBox.setActivated(task.getBox());用于激活/取消激活复选框。使用checkBox.setChecked(task.getBox());设置选中/未选中。

相关问题