此方法主要是通过实体类,进行赋值取值来判断 是否选中取消CheckBox
在实体类中定义isChoosed (初始值false 未选中)
public class ShopGoodsSelectBean {
private int shopId;
private int position;
private boolean isChoosed;
public ShopGoodsSelectBean(int shopId, int position) {
this.shopId = shopId;
this.position = position;
}
public int getShopId() {
return shopId;
}
public void setShopId(int shopId) {
this.shopId = shopId;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}}
在获取的数据类中添加一个是否选中状态,在onBindViewHolder 中进行赋值判断
// 赋值之前取消CheckBox监听
checkBox.setOnCheckedChangeListener(null);
checkBox.setChecked(data.isChecked);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
data.isChecked =isChecked;
}
});
网友评论