该问题有两种解决方案,个人目前所实现了的。
1.用HashMap保存checkbox的状态值。
HashMap<Integer, Boolean> state = new HashMap<Integer,Boolean>();
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked)
{
state.put(position, isChecked);
System.out.println("复选框以选中,选中的行数为:" + temp_position);
}else{
state.remove(position);
}
}
在getView()方法里面: holder.cbox.setChecked(state.get(position)==null? false : true);
2.(不推荐使用,因为会产生许多垃圾对象)
public View getView(int position, View convertView, ViewGroup parent)在每次传进convertView时候,设为null。
然后每调用一次getView就产生一个view对象。