| | |
| | | import com.application.zhangshi_app_android.ui.function.FamilyMemorabiliaActivityViewModel; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected MyViewHolder getViewHolder(ItemFamilyMemorabiliaBinding itemBind) { |
| | | protected MyViewHolder getViewHolder(ItemFamilyMemorabiliaBinding itemBind,int viewType) { |
| | | return new MyViewHolder(itemBind); |
| | | } |
| | | |
| | |
| | | holder.getBinding().checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
| | | @Override |
| | | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| | | List<FamilyMemorabiliaBean> list = new ArrayList<>(Objects.requireNonNull(viewModel.getCheckListLiveData().getValue())); |
| | | if (viewModel.getCheckListLiveData().getValue() == null){ |
| | | viewModel.getCheckListLiveData().setValue(new ArrayList<>()); |
| | | } |
| | | List<FamilyMemorabiliaBean> list = new ArrayList<>(viewModel.getCheckListLiveData().getValue()); |
| | | if (isChecked){ |
| | | list.add(mDataList.get(position)); |
| | | if (!list.contains(mDataList.get(position))){ |
| | | list.add(mDataList.get(position)); |
| | | } |
| | | }else{ |
| | | list.remove(mDataList.get(position)); |
| | | } |
| | | viewModel.getCheckListLiveData().postValue(list); |
| | | viewModel.getCheckListLiveData().setValue(list); |
| | | } |
| | | }); |
| | | holder.getBinding().checkbox.setChecked(viewModel.getCheckListLiveData().getValue().contains(mDataList.get(position))); |