利用接口传回商家集合 在根据获取的选中数量 与 总相同则勾上 小于则不打勾
myAdapter_boss.getSumAndMoney(new MyAdapter_Boss.GetSumAndMoneyCall() {
@Override
public void getSumData(List<GoodsBean.DataBean> list) {
double totalPrice = 0;
int num = 0;
//所有商品总数,和上面的数量做比对,如果两者相等,则说明全选
int totalNum = 0;
for (int a = 0; a < list.size(); a++) {
//获取商家里商品
List<GoodsBean.DataBean.ListBean> listAll = list.get(a).getList();
for (int i = 0; i < listAll.size(); i++) {
totalNum = totalNum + listAll.get(i).getNum();
//取选中的状态
if (listAll.get(i).isFlag()) {
totalPrice = totalPrice + (listAll.get(i).getPrice() * listAll.get(i).getNum());
num = num + listAll.get(i).getNum();
}
}
}
if (num < totalNum) {
//不是全部选中
ivCricle.setChecked(false);
} else {
//是全部选中
ivCricle.setChecked(true);
}
allPrice.setText("合计:" + totalPrice);
sumPriceTxt.setText("去结算(" + num + ")");
}
});
给全选复选框设置点击事件 点击以后调用checkSeller()方法传入现在的状态 给数据设置全反选
ivCricle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
checkSeller(ivCricle.isChecked());
myAdapter_boss.notifyDataSetChanged();
}
});
private void checkSeller(boolean bool) {
double totalPrice = 0;
int num = 0;
for (int a = 0; a < dataOne.size(); a++) {
//遍历商家,改变状态
GoodsBean.DataBean dataBean = dataOne.get(a);
dataBean.setBoss_flag(bool);
List<GoodsBean.DataBean.ListBean> listAll = dataOne.get(a).getList();
for (int i = 0; i < listAll.size(); i++) {
//遍历商品,改变状态
listAll.get(i).setFlag(bool);
totalPrice = totalPrice + (listAll.get(i).getPrice() * listAll.get(i).getNum());
num = num + listAll.get(i).getNum();
}
}
if (bool) {
allPrice.setText("合计:" + totalPrice);
sumPriceTxt.setText("去结算(" + num + ")");
} else {
allPrice.setText("合计:0.00");
sumPriceTxt.setText("去结算(0)");
}
}