private List<String>
list;
private final HashMap<Integer
, Boolean>
ischeck;
public Mybase() {
ischeck =
new HashMap<>()
;
list =
new ArrayList<>()
;
for (
int i =
0; i <
30; i++) {
list.add(
"数量" + i)
;
ischeck.put(i
, false)
;
}
//错乱问题解决 以及单选的调用
holder.
item_img.setImageResource(R.drawable.
wx)
;
holder.
item_checkbox.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// ischeck.put(position, !ischeck.get(position));
// notifyDataSetChanged();
dogxuan(
position)
;
}
})
;
holder.
item_checkbox.setChecked(
ischeck.get(position))
;
}
//全选
public void selectall() {
Set<Map.Entry<Integer
, Boolean>> entries =
ischeck.entrySet()
;
boolean nocheckall =
false;
for (Map.Entry<Integer
, Boolean> entry : entries) {
Boolean value = entry.getValue()
;
if (!value) {
nocheckall =
true;
break;
}
}
for (Map.Entry<Integer
, Boolean> entry : entries) {
entry.setValue(nocheckall)
;
}
notifyDataSetChanged()
;
}
//反选
public void noxuan() {
Set<Map.Entry<Integer
, Boolean>> entries =
ischeck.entrySet()
;
for (Map.Entry<Integer
, Boolean> entry : entries) {
entry.setValue(!entry.getValue())
;
}
notifyDataSetChanged()
;
}
//单选
public void dogxuan(
int position) {
Set<Map.Entry<Integer
, Boolean>> entries =
ischeck.entrySet()
;
for (Map.Entry<Integer
, Boolean> entry : entries) {
entry.setValue(
false)
;
}
ischeck.put(position
, true)
;
notifyDataSetChanged()
;
}