美文网首页
listview/recyclerview 滑动自动触发setO

listview/recyclerview 滑动自动触发setO

作者: 菜鸟考官 | 来源:发表于2018-06-23 16:02 被阅读0次
此方法主要是通过实体类,进行赋值取值来判断 是否选中取消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;
           }
       });

相关文章

网友评论

      本文标题:listview/recyclerview 滑动自动触发setO

      本文链接:https://www.haomeiwen.com/subject/wntdyftx.html