public interface MyCheckInterface {
boolean isSingleCheckMode();
void setCheckMode(boolean isSingleCheck);
@NonNull
List<Model> getCheck();
void setCheck(Model model, boolean isCheck);
boolean isCheck(Model model);
}
实现该接口
@Override
public boolean isSingleCheckMode() {
return isSingle;
}
@Override
public void setCheckMode(boolean isSingleCheck) {
this.isSingle = isSingleCheck;
}
@NonNull
@Override
public List<Model> getCheck() {
return ModelListGet;
}
@Override
public void setCheck(Model model, boolean isCheck) {
if (isCheck){
if (isSingle){
Iterator entries = cbMap.entrySet().iterator();
while (entries.hasNext()){
Map.Entry entry = (Map.Entry) entries.next();
Model key = (Model) entry.getKey();
CheckBox value = (CheckBox) entry.getValue();
if (model != key){
value.setChecked(false);
}else {
value.setChecked(true);
}
}
if (ModelListGet.size()!=0)
disCheck(ModelListGet.get(0));
ModelListGet.clear();
}
check(model);
}else {
disCheck(model);
}
}
public void check(Model model){
UI操作+数据保存
}
public void disCheck(Model model){
UI操作+数据删除
}
@Override
public boolean isCheck(Model model) {
if (ModelListGet.contains(model)){
return true;
}else {
return false;
}
}