ProductCatagoryModel
package com.example.simluateexam.model; import com.example.simluateexam.bean.ProductCatagoryBean; import com.example.simluateexam.presenter.ProductCatagoryPresenterImp; import com.example.simluateexam.utils.RetrofitUtils; import java.util.ArrayList; import java.util.List; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; /** * Created by john on 2018/6/29. */ public class ProductCatagoryModel { public void getProduct(String cid, final ProductCatagoryPresenterImp productCatagoryPresenterImp){ RetrofitUtils.getInstance().getProduct(cid).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<ProductCatagoryBean>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(ProductCatagoryBean productCatagoryBean) { List<List<ProductCatagoryBean.DataBean.ListBean>> childList=new ArrayList<>(); List<String> groupList=new ArrayList<>(); List<ProductCatagoryBean.DataBean> data = productCatagoryBean.getData(); for (int i = 0; i < data.size(); i++) { String name = data.get(i).getName(); groupList.add(name); List<ProductCatagoryBean.DataBean.ListBean> list = data.get(i).getList(); childList.add(list); } productCatagoryPresenterImp.productSuccess(groupList,childList); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); } }
CartModel
package com.example.simluateexam.model; import com.example.simluateexam.bean.GetCartsBean; import com.example.simluateexam.bean.MerChantBean; import com.example.simluateexam.presenter.CartPresenterImp; import com.example.simluateexam.utils.RetrofitUtils; import java.util.ArrayList; import java.util.List; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; /** * Created by john on 2018/6/29. */ public class CartModel { public void getCart(String uid, final CartPresenterImp presenterImp){ RetrofitUtils.getInstance().getCarts(uid).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<GetCartsBean>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(GetCartsBean bean) { List<MerChantBean> groupList=new ArrayList<>(); List<List<GetCartsBean.DataBean.ListBean>> childList=new ArrayList<>(); List<GetCartsBean.DataBean> data = bean.getData(); for (int i = 0; i < data.size(); i++) { GetCartsBean.DataBean dataBean = data.get(i); MerChantBean merChantBean=new MerChantBean(); merChantBean.setMerChantName(dataBean.getSellerName()); merChantBean.setMerChantId(dataBean.getSellerid()); merChantBean.setMerChantSelected(isMerChantAllSelect(dataBean)); groupList.add(merChantBean); List<GetCartsBean.DataBean.ListBean> listBeans = dataBean.getList(); childList.add(listBeans); } presenterImp.getCartSuccess(groupList,childList); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); } private boolean isMerChantAllSelect(GetCartsBean.DataBean dataBean) { List<GetCartsBean.DataBean.ListBean> list = dataBean.getList(); for (int i = 0; i < list.size(); i++) { GetCartsBean.DataBean.ListBean listBean = list.get(i); if (0==listBean.getSelected()){ return false; } } return true; } }
MainActivity
package com.example.simluateexam; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.widget.ExpandableListView; import com.example.simluateexam.adapter.ElvRightAdapter; import com.example.simluateexam.adapter.RvLeftAdapter; import com.example.simluateexam.bean.CatagoryBean; import com.example.simluateexam.bean.ProductCatagoryBean; import com.example.simluateexam.presenter.CatagoryPresenterImp; import com.example.simluateexam.presenter.ProductCatagoryPresenterImp; import com.example.simluateexam.view.CatagoryView; import com.example.simluateexam.view.OnItemClickListener; import com.example.simluateexam.view.ProductCatagoryView; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; public class MainActivity extends AppCompatActivity implements CatagoryView,ProductCatagoryView{ @BindView(R.id.rv_left) RecyclerView rvLeft; @BindView(R.id.elv_right) ExpandableListView elvRight; private CatagoryPresenterImp catagoryPresenterImp; private ProductCatagoryPresenterImp productCatagoryPresenterImp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); initData(); } private void initData() { catagoryPresenterImp = new CatagoryPresenterImp(this); productCatagoryPresenterImp = new ProductCatagoryPresenterImp(this); catagoryPresenterImp.getCatagory(); rvLeft.setLayoutManager(new LinearLayoutManager(MainActivity.this,RecyclerView.VERTICAL,false)); rvLeft.addItemDecoration(new DividerItemDecoration(MainActivity.this,DividerItemDecoration.VERTICAL)); } @Override protected void onDestroy() { super.onDestroy(); catagoryPresenterImp.getCatagory(); productCatagoryPresenterImp.detach(); } @Override public void catagorySuccess(final CatagoryBean bean) { runOnUiThread(new Runnable() { @Override public void run() { final List<CatagoryBean.DataBean> list = bean.getData(); final RvLeftAdapter rvLeftAdapter=new RvLeftAdapter(list,MainActivity.this); rvLeft.setAdapter(rvLeftAdapter); int cid = list.get(0).getCid(); productCatagoryPresenterImp.getProduct(cid+""); rvLeftAdapter.changeCheck(0,true); rvLeftAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(int position) { rvLeftAdapter.changeCheck(position,true); productCatagoryPresenterImp.getProduct(list.get(position).getCid()+""); } @Override public void onItemLongClick(int position) { } }); } }); } @Override public void catagoryFaile(String msg) { } @Override public void productSuccess(final List<String> groupList, final List<List<ProductCatagoryBean.DataBean.ListBean>> childList) { runOnUiThread(new Runnable() { @Override public void run() { ElvRightAdapter elvRightAdapter=new ElvRightAdapter(groupList,childList,MainActivity.this); elvRight.setAdapter(elvRightAdapter); for (int i = 0; i < groupList.size(); i++) { elvRight.expandGroup(i); } } }); } @Override public void productFaile(String msg) { } }
CartActivity
package com.example.simluateexam; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.ExpandableListView; import android.widget.TextView; import com.example.simluateexam.adapter.CartAdapter; import com.example.simluateexam.bean.GetCartsBean; import com.example.simluateexam.bean.MerChantBean; import com.example.simluateexam.presenter.CartPresenterImp; import com.example.simluateexam.view.CartView; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; public class CartActivity extends AppCompatActivity implements CartView{ @BindView(R.id.elv) ExpandableListView elv; @BindView(R.id.cbAll) CheckBox cbAll; @BindView(R.id.tvMoney) TextView tvMoney; @BindView(R.id.tvTotal) TextView tvTotal; private CartPresenterImp cartPresenterImp; private CartAdapter cartAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cart); ButterKnife.bind(this); initData(); } private void initData() { cartPresenterImp = new CartPresenterImp(this); cartPresenterImp.getCart("14509"); cbAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (cartAdapter!=null){ cartAdapter.allCheckState(cbAll.isChecked()); } } }); } @Override protected void onDestroy() { super.onDestroy(); cartPresenterImp.detach(); } @Override public void getCartSuccess(final List<MerChantBean> groupList, final List<List<GetCartsBean.DataBean.ListBean>> childList) { runOnUiThread(new Runnable() { @Override public void run() { cartAdapter = new CartAdapter(groupList,childList,CartActivity.this,cartPresenterImp); elv.setAdapter(cartAdapter); String[] strings = cartAdapter.totalPrice(); tvMoney.setText("总价:"+strings[0]+"元"); tvTotal.setText("去结算"+strings[1]+"个"); for (int i = 0; i < groupList.size(); i++) { elv.expandGroup(i); } cbAll.setChecked(isMerChantAddCheck(groupList)); } }); } private boolean isMerChantAddCheck(List<MerChantBean> groupList) { for (int i = 0; i < groupList.size(); i++) { MerChantBean merChantBean = groupList.get(i); if (!merChantBean.isMerChantSelected()){ return false; } } return true; } }
AddSubView
package com.example.simluateexam.widgt; import android.content.Context; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.example.simluateexam.R; /** * Created by john on 2018/6/29. */ public class AddSubView extends LinearLayout{ private TextView add; private TextView num; private TextView sub; public AddSubView(Context context) { this(context,null); } public AddSubView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); View view= LayoutInflater.from(context).inflate(R.layout.as_view,this,true); add = view.findViewById(R.id.add); num = view.findViewById(R.id.num); sub = view.findViewById(R.id.sub); } public void setNum(String s){ num.setText(s); } public String getNum(){ return num.getText().toString(); } public void setAddOnClick(OnClickListener onClick){ add.setOnClickListener(onClick); } public void setSubOnClick(OnClickListener onClick){ sub.setOnClickListener(onClick); } }
RvLeftAdapter
package com.example.simluateexam.adapter; import android.content.Context; import android.graphics.Color; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.example.simluateexam.R; import com.example.simluateexam.bean.CatagoryBean; import com.example.simluateexam.view.OnItemClickListener; import java.util.List; /** * Created by john on 2018/6/29. */ public class RvLeftAdapter extends RecyclerView.Adapter<RvLeftAdapter.MyViewHolder>{ private List<CatagoryBean.DataBean> list; private Context context; private OnItemClickListener onItemClickListener; public RvLeftAdapter(List<CatagoryBean.DataBean> list, Context context) { this.list = list; this.context = context; } public void setOnItemClickListener(OnItemClickListener onItemClickListener) { this.onItemClickListener = onItemClickListener; } @NonNull @Override public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view= LayoutInflater.from(context).inflate(R.layout.rvleft_item,parent,false); MyViewHolder viewHolder=new MyViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) { holder.tv.setText(list.get(position).getName()); if (list.get(position).getChecked()){ holder.tv.setTextColor(Color.WHITE); holder.tv.setBackgroundColor(Color.BLACK); }else{ holder.tv.setTextColor(Color.BLACK); holder.tv.setBackgroundColor(Color.WHITE); } holder.tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (onItemClickListener!=null){ onItemClickListener.onItemClick(position); } } }); } @Override public int getItemCount() { return list.size(); } class MyViewHolder extends RecyclerView.ViewHolder{ private final TextView tv; public MyViewHolder(View itemView) { super(itemView); tv = itemView.findViewById(R.id.rv_left_tv); } } public void changeCheck(int position,boolean b){ for (int i = 0; i < list.size(); i++) { list.get(i).setChecked(false); } list.get(position).setChecked(b); notifyDataSetChanged(); } }
ElvRigthAdapter
package com.example.simluateexam.adapter; import android.content.Context; import android.content.Intent; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.TextView; import com.example.simluateexam.CartActivity; import com.example.simluateexam.R; import com.example.simluateexam.ShopCartActivity; import com.example.simluateexam.bean.ProductCatagoryBean; import com.example.simluateexam.view.OnItemClickListener; import org.w3c.dom.Text; import java.util.List; /** * Created by john on 2018/6/29. */ public class ElvRightAdapter extends BaseExpandableListAdapter{ private List<String> groupList; private List<List<ProductCatagoryBean.DataBean.ListBean>> childList; private Context context; private TextView tv; public ElvRightAdapter(List<String> groupList, List<List<ProductCatagoryBean.DataBean.ListBean>> childList, Context context) { this.groupList = groupList; this.childList = childList; this.context = context; } @Override public int getGroupCount() { return groupList.size(); } @Override public int getChildrenCount(int groupPosition) { return 1; } @Override public Object getGroup(int groupPosition) { return groupList.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return childList.get(groupPosition).get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { convertView= LayoutInflater.from(context).inflate(R.layout.rvleft_item,parent,false); tv = convertView.findViewById(R.id.rv_left_tv); tv.setText(groupList.get(groupPosition)); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { convertView=LayoutInflater.from(context).inflate(R.layout.elvright_item,parent,false); RecyclerView rv=convertView.findViewById(R.id.elv_right_rv); rv.setLayoutManager(new GridLayoutManager(context,3)); List<ProductCatagoryBean.DataBean.ListBean> listBeans = childList.get(groupPosition); RigthRvAdapter rigthRvAdapter=new RigthRvAdapter(listBeans,context); rv.setAdapter(rigthRvAdapter); rigthRvAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(int position) { Intent intent=new Intent(context, CartActivity.class); context.startActivity(intent); } @Override public void onItemLongClick(int position) { } }); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } }
RigthRvAdapter
package com.example.simluateexam.adapter; import android.content.Context; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.example.simluateexam.R; import com.example.simluateexam.bean.ProductCatagoryBean; import com.example.simluateexam.view.OnItemClickListener; import com.facebook.drawee.view.SimpleDraweeView; import org.w3c.dom.Text; import java.util.List; /** * Created by john on 2018/6/29. */ public class RigthRvAdapter extends RecyclerView.Adapter<RigthRvAdapter.MyViewHolder>{ private List<ProductCatagoryBean.DataBean.ListBean> list; private Context context; private OnItemClickListener onItemClickListener; public RigthRvAdapter(List<ProductCatagoryBean.DataBean.ListBean> list, Context context) { this.list = list; this.context = context; } public void setOnItemClickListener(OnItemClickListener onItemClickListener) { this.onItemClickListener = onItemClickListener; } @NonNull @Override public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view= LayoutInflater.from(context).inflate(R.layout.rightrv_item,parent,false); MyViewHolder viewHolder=new MyViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) { holder.sdv.setImageURI(list.get(position).getIcon()); holder.tv.setText(list.get(position).getName()); holder.sdv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (onItemClickListener!=null){ onItemClickListener.onItemClick(position); } } }); } @Override public int getItemCount() { return list.size(); } class MyViewHolder extends RecyclerView.ViewHolder{ private final SimpleDraweeView sdv; private final TextView tv; public MyViewHolder(View itemView) { super(itemView); sdv = itemView.findViewById(R.id.sdv); tv = itemView.findViewById(R.id.rightrv_tv); } } }
package com.example.simluateexam.adapter; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import com.example.simluateexam.MyApplication; import com.example.simluateexam.R; import com.example.simluateexam.bean.GetCartsBean; import com.example.simluateexam.bean.MerChantBean; import com.example.simluateexam.dao.UserDao; import com.example.simluateexam.dao.UserDaoDao; import com.example.simluateexam.presenter.CartPresenterImp; import com.example.simluateexam.presenter.DeletePresenterImp; import com.example.simluateexam.presenter.GetCartsPresenterImp; import com.example.simluateexam.presenter.UpdatePresenterImp; import com.example.simluateexam.view.DeleteView; import com.example.simluateexam.view.UpdateView; import com.example.simluateexam.widgt.AddSubView; import com.facebook.drawee.view.SimpleDraweeView; import java.util.List; /** * Created by john on 2018/6/29. */ public class CartAdapter extends BaseExpandableListAdapter implements UpdateView,DeleteView{ private List<MerChantBean> groupList; private List<List<GetCartsBean.DataBean.ListBean>> childList; private Context context; private CartPresenterImp cartPresenterImp; private final UpdatePresenterImp updatePresenterImp; private final DeletePresenterImp deletePresenterImp; private int uid=14509; private int prdocutIndex; private int groupP; private boolean checked; private static final int GETCARTS=0; private static final int UPDATE_PRODUCT=1; private static final int UPDATE_MERCHANT=2; private static int state=GETCARTS; private boolean allCheck; private final UserDaoDao userDaoDao; public CartAdapter(List<MerChantBean> groupList, List<List<GetCartsBean.DataBean.ListBean>> childList, Context context, CartPresenterImp cartPresenterImp) { this.groupList = groupList; this.childList = childList; this.context = context; this.cartPresenterImp = cartPresenterImp; updatePresenterImp = new UpdatePresenterImp(this); deletePresenterImp = new DeletePresenterImp(this); userDaoDao = MyApplication.getInstance().getDaoSession().getUserDaoDao(); } @Override public int getGroupCount() { return groupList.size(); } @Override public int getChildrenCount(int groupPosition) { return childList.get(groupPosition).size(); } @Override public Object getGroup(int groupPosition) { return groupList.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return childList.get(groupPosition).get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { convertView= LayoutInflater.from(context).inflate(R.layout.group_item,parent,false); final CheckBox cbMerChant = convertView.findViewById(R.id.cbMerchant); TextView tvMerChant = convertView.findViewById(R.id.tvMerchant); tvMerChant.setText(groupList.get(groupPosition).getMerChantName()); cbMerChant.setChecked(groupList.get(groupPosition).isMerChantSelected()); cbMerChant.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { state=UPDATE_PRODUCT; prdocutIndex=0; groupP=groupPosition; checked = cbMerChant.isChecked(); updateMerChant(); } }); return convertView; } @Override public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { convertView=LayoutInflater.from(context).inflate(R.layout.child_item,parent,false); final CheckBox cb_shop = convertView.findViewById(R.id.cb_shop); SimpleDraweeView sdv_child=convertView.findViewById(R.id.sdv_child); TextView tvTitle=convertView.findViewById(R.id.tv_title); TextView tvPrice=convertView.findViewById(R.id.tv_price); AddSubView as=convertView.findViewById(R.id.as); TextView tvDel = convertView.findViewById(R.id.tvDel); final GetCartsBean.DataBean.ListBean listBean = childList.get(groupPosition).get(childPosition); cb_shop.setChecked(listBean.getSelected()==1?true:false); tvTitle.setText(listBean.getTitle()); tvPrice.setText("¥:"+listBean.getPrice()); String s = listBean.getImages().split("\\|")[0]; sdv_child.setImageURI(s); as.setNum(listBean.getNum()+""); cb_shop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { state=GETCARTS; groupP=groupPosition; String merChantId = groupList.get(groupPosition).getMerChantId(); int pid = listBean.getPid(); boolean cb_shopChecked = cb_shop.isChecked(); updatePresenterImp.updateCart(uid+"",merChantId,pid+"",cb_shopChecked?"1":"0",pid+""); } }); as.setAddOnClick(new View.OnClickListener() { @Override public void onClick(View v) { state=GETCARTS; String merChantId = groupList.get(groupPosition).getMerChantId(); int pid = listBean.getPid(); int num = listBean.getNum(); num+=1; String isCheck = cb_shop.isChecked() ? "1" : "0"; updatePresenterImp.updateCart(uid+"",merChantId,pid+"",isCheck,num+""); List<UserDao> userDaos = userDaoDao.loadAll(); for (int i = 0; i < userDaos.size(); i++) { Long id = userDaos.get(i).getId(); Toast.makeText(context,id+"",Toast.LENGTH_SHORT).show(); } } }); as.setSubOnClick(new View.OnClickListener() { @Override public void onClick(View v) { state=GETCARTS; int num = listBean.getNum(); if (num<=1){ Toast.makeText(context,"数量不能小于1",Toast.LENGTH_SHORT).show(); return; } num-=1; String merChantId = groupList.get(groupPosition).getMerChantId(); int pid = listBean.getPid(); String isCheck = cb_shop.isChecked() ? "1" : "0"; updatePresenterImp.updateCart(uid+"",merChantId,pid+"",isCheck,num+""); } }); tvDel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { state=GETCARTS; int pid = listBean.getPid(); deletePresenterImp.deleteCart(uid+"",pid+""); } }); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } @Override public void deleteSuccess() { cartPresenterImp.getCart(uid+""); } @Override public void updateSuccess() { switch (state){ case GETCARTS: prdocutIndex=0; groupP=0; cartPresenterImp.getCart(uid+""); break; case UPDATE_PRODUCT: prdocutIndex++; if (prdocutIndex<childList.get(groupP).size()){ updateMerChant(); }else{ state=GETCARTS; updateSuccess(); } break; case UPDATE_MERCHANT: prdocutIndex++; if (prdocutIndex<childList.get(groupP).size()){ updateMerChant(allCheck); }else{ prdocutIndex=0; groupP++; if (groupP<groupList.size()){ updateMerChant(allCheck); }else{ state=GETCARTS; updateSuccess(); } } break; } } private void updateMerChant(boolean b) { MerChantBean merChantBean = groupList.get(groupP); String merChantId = merChantBean.getMerChantId(); GetCartsBean.DataBean.ListBean listBean = childList.get(groupP).get(prdocutIndex); int pid = listBean.getPid(); int num = listBean.getNum(); updatePresenterImp.updateCart(uid+"",merChantId,pid+"",b?"1":"0",num+""); } private void updateMerChant() { MerChantBean merChantBean = groupList.get(groupP); String merChantId = merChantBean.getMerChantId(); GetCartsBean.DataBean.ListBean listBean = childList.get(groupP).get(prdocutIndex); int num = listBean.getNum(); int pid = listBean.getPid(); updatePresenterImp.updateCart(uid+"",merChantId,pid+"",checked?"1":"0",num+""); } public String[] totalPrice(){ double sum=0; int num=0; for (int i = 0; i < groupList.size(); i++) { for (int j = 0; j < childList.get(i).size(); j++) { GetCartsBean.DataBean.ListBean listBean = childList.get(i).get(j); if (listBean.getSelected()==1){ sum+=listBean.getPrice()*listBean.getNum(); num+=listBean.getNum(); } } } return new String[]{sum+"",num+""}; } public void allCheckState(boolean b){ allCheck=b; state=UPDATE_MERCHANT; updateMerChant(b); } }