## MainActivity
适配
adapter.setmItemBack(new MyAdapter.mItemBack() {
@Override
public void getmItemBack() {
boolean ck = true;
for (int i = 0; i < result.size(); i++) {
boolean orck = ck & result.get(i).isOkcheck();
for (int j = 0; j < result.get(i).getShoppingCartList().size(); j++) {
boolean mck = ck & result.get(i).getShoppingCartList().get(j).isItemcheck();
ck = ck & orck & mck;
}
}
qvan.setChecked(ck);
tonum();
toprice();
}
});
全选
qvan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = qvan.isChecked();
for (int i = 0; i < result.size(); i++) {
result.get(i).setOkcheck(checked);
for (int j = 0; j < result.get(i).getShoppingCartList().size(); j++) {
result.get(i).getShoppingCartList().get(j).setItemcheck(checked);
}
}
tonum();
toprice();
adapter.notifyDataSetChanged();
}
});
价格
public void toprice() {
double prices = 0;
for (int i = 0; i < result.size(); i++) {
for (int j = 0; j < result.get(i).getShoppingCartList().size(); j++) {
if (result.get(i).getShoppingCartList().get(j).isItemcheck() == true) {
double price = result.get(i).getShoppingCartList().get(j).getPrice();
int count = result.get(i).getShoppingCartList().get(j).getCount();
double v = price * count;
prices = prices + v;
}
}
zong.setText(prices + "");
}
}
数量
public void tonum() {
double shuliangs = 0;
for (int i = 0; i < result.size(); i++) {
for (int j = 0; j < result.get(i).getShoppingCartList().size(); j++) {
if (result.get(i).getShoppingCartList().get(j).isItemcheck() == true) {
int count = result.get(i).getShoppingCartList().get(j).getCount();
shuliangs += count;
}
}
shuliang.setText(shuliangs + "");
}
}
适配器一
boolean okcheck = result.get(position).isOkcheck();
holder1.did_checkbox.setChecked(okcheck);
holder1.did_checkbox.setOnCheckedChangeListener(null);
holder1.did_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
for (int i = 0; i < result.get(position).getShoppingCartList().size(); i++) {
result.get(position).getShoppingCartList().get(i).setItemcheck(isChecked);
}
result.get(position).setOkcheck(isChecked);
myadapter2.notifyDataSetChanged();
mItemBack.getmItemBack();
}
});
myadapter2.setmItemOnclick(new Myadapter2.mItemOnclick() {
@Override
public void getmItemOnclick() {
boolean item = true;
for (int i = 0; i < result.get(position).getShoppingCartList().size(); i++) {
if (item = item & result.get(position).getShoppingCartList().get(i).isItemcheck() == true) {
result.get(position).getShoppingCartList().get(i).setItemcheck(item);
}
}
holder1.did_checkbox.setChecked(item);
myadapter2.notifyDataSetChanged();
mItemBack.getmItemBack();
}
});
适配器二
myholder.son_checkbox.setOnCheckedChangeListener(null);
boolean itemcheck = listBeans.get(position).isItemcheck();
myholder.son_checkbox.setChecked(itemcheck);
myholder.son_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
listBeans.get(position).setItemcheck(isChecked);
mItemOnclick.getmItemOnclick();
}
});
适配器加减器
myholder.zidingyi.count(listBeans.get(position).getCount());
myholder.zidingyi.setmDianjiBack(new SerichView.mDianjiBack() {
@Override
public void jia(int aums) {
listBeans.get(position).setCount(aums);
mItemOnclick.getmItemOnclick();
}
@Override
public void jian(int anums) {
listBeans.get(position).setCount(anums);
mItemOnclick.getmItemOnclick();
}
});