全选控制所有 商家商品,商家控制商品,全选价格联动
checkall.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
for (int i = 0; i < shoplist.size(); i++) { // 全选遍历循环商家
shoplist.get(i).setIschecked(checkall.isChecked());
for (int j = 0; j < shoplist.get(i).getList().size(); j++) { //商家遍历循环商品
shoplist.get(i).getList().get(j).setIsgoodIschecked(checkall.isChecked());
}
}
shopAdapter.notifyDataSetChanged(); //刷新商家适配器
calculateTotalCount(); 价格的方法
}
//价格
private void calculateTotalCount() {
//外层条目 //对总价进行计算
double totalCount = 0;
for (int i = 0; i < shoplist.size(); i++) {
//内层条目
for (int j = 0; j < shoplist.get(i).getList().size(); j++) {
//判断内层条目是否勾选
if (shoplist.get(i).getList().get(j).isgoodIschecked == true){
//获取商品数据*商品价格
double price = shoplist.get(i).getList().get(j).getPrice();
int defalutNumber = shoplist.get(i).getList().get(j).getNum();
double goodsPrice = price * defalutNumber;
totalCount = totalCount+goodsPrice;
}
}
}
allprice.setText(String.valueOf(totalCount));
}
});
在商家的adapter遍历循环
//全选
viewHolder.shopcheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
for (int j = 0; j < list.get(i).getList().size(); j++) {
list.get(i).getList().get(j).setIsgoodIschecked(b);
}
goodAdapter.notifyDataSetChanged(); //刷新商品的适配器
}
});