购物车

fragmenter

public class Shou1Fragmenter extends Fragment implements IManintenter, ZongJiaintenter {
@BindView(R.id.quanxuan)
CheckBox quanxuan;
@BindView(R.id.zongjia)
TextView zongjia;
@BindView(R.id.shangpinRecyclerView)
RecyclerView shangpinRecyclerView;
Unbinder unbinder;
private ShangPinAdapter pinAdapter;
private List<GouWuChBean.DataBean> data;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.shou1layout, container, false);
    unbinder = ButterKnife.bind(this, view);
    if (getUserVisibleHint()) {
        GouWuChePager gouWuChePager = new GouWuChePager(this);
        gouWuChePager.getgouwuchepresenter();
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        shangpinRecyclerView.setLayoutManager(manager);
        pinAdapter = new ShangPinAdapter(getActivity(),this);
        shangpinRecyclerView.setAdapter(pinAdapter);
    }

    return view;
}

@Override
public void getintenter(GouWuChBean gouWuChBean) {
    data = gouWuChBean.getData();
    pinAdapter.setData(data);
    pinAdapter.setQuanxuan(quanxuan);
}

@Override
public void onDestroyView() {
    super.onDestroyView();
    unbinder.unbind();
}

@OnClick(R.id.quanxuan)
public void onViewClicked() {
    boolean checked = quanxuan.isChecked();
    for (int i = 0; i <data.size(); i++) {
        data.get(i).setClick(checked);
        List<GouWuChBean.DataBean.ListBean> list = data.get(i).getList();
        for (int j = 0; j <list.size() ; j++) {
            list.get(j).setClick(checked);
        }
    }
    getzongjia();
    pinAdapter.notifyDataSetChanged();
}

private void getzongjia(){
    double zong=0;
    for (int i = 0; i <data.size() ; i++) {
        List<GouWuChBean.DataBean.ListBean> list = data.get(i).getList();
        for (int j = 0; j <list.size() ; j++) {
            boolean click = list.get(j).isClick();
            if (click) {
                String num = list.get(j).getNum();
                String price = list.get(j).getPrice();
                int i1 = Integer.parseInt(num);
                double v = Double.parseDouble(price);
                zong += i1 * v;
            }
        }
    }
    zongjia.setText("总价为:¥"+zong+"");
}

@Override
public void zong() {
    getzongjia();
}

}
*

商家adapter

public class ShangPinAdapter extends RecyclerView.Adapter<ShangPinAdapter.MMA> {
Context context;
LayoutInflater inflater;
private ZiAdapter adapter;

private ZongJiaintenter zongJiaintenter;

public ShangPinAdapter(Context contexts, ZongJiaintenter zongJiaintenters) {
    this.zongJiaintenter = zongJiaintenters;
    this.context = contexts;
    this.inflater = LayoutInflater.from(context);
}

private CheckBox quanxuan;

public void setQuanxuan(CheckBox quanxuan) {
    this.quanxuan = quanxuan;
}

@NonNull
@Override
public MMA onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = inflater.inflate(R.layout.gouwuchelayout, viewGroup, false);
    MMA mma = new MMA(view);
    return mma;
}

@Override
public void onBindViewHolder(@NonNull MMA mma, final int i) {
    String sellerName = data.get(i).getSellerName();
    mma.funame.setText(sellerName);
    boolean click = data.get(i).isClick();
    mma.fuclick.setChecked(click);
    LinearLayoutManager manager = new LinearLayoutManager(context);
    manager.setOrientation(LinearLayoutManager.VERTICAL);
    mma.ziRecyclerView.setLayoutManager(manager);
    adapter = new ZiAdapter(context,zongJiaintenter);
    adapter.setFuclick(mma.fuclick, data);
    adapter.setQuanxuan(quanxuan);
    mma.ziRecyclerView.setAdapter(adapter);
    final List<GouWuChBean.DataBean.ListBean> list = data.get(i).getList();
    adapter.setData(list);
    mma.fuclick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CheckBox box = (CheckBox) v;
            boolean checked = box.isChecked();
            data.get(i).setClick(checked);
            for (int j = 0; j < list.size(); j++) {
                list.get(j).setClick(checked);
            }
            boolean quabxuanss = quabxuanss();
            quanxuan.setChecked(quabxuanss);
            zongJiaintenter.zong();
            notifyDataSetChanged();
        }
    });
}

private boolean quabxuanss() {
    for (int i = 0; i < data.size(); i++) {
        boolean click = data.get(i).isClick();
        if (!click) {
            return false;
        }
    }
    return true;
}

@Override
public int getItemCount() {
    return data.size();
}

List<GouWuChBean.DataBean> data = new ArrayList<>();

public void setData(List<GouWuChBean.DataBean> datas) {
    this.data.clear();
    this.data.addAll(datas);
    notifyDataSetChanged();
}

public class MMA extends RecyclerView.ViewHolder {

    private final CheckBox fuclick;
    private final TextView funame;
    private final RecyclerView ziRecyclerView;

    public MMA(@NonNull View itemView) {
        super(itemView);
        fuclick = itemView.findViewById(R.id.fuclick);
        funame = itemView.findViewById(R.id.funame);
        ziRecyclerView = itemView.findViewById(R.id.ziRecyclerView);
    }
}

}

商品adapter

public class ZiAdapter extends RecyclerView.Adapter<ZiAdapter.BBA> {
Context context;
LayoutInflater inflater;
private ZongJiaintenter zongJiaintenter;
public ZiAdapter(Context context1,ZongJiaintenter zongJiaintenters) {
this.zongJiaintenter=zongJiaintenters;
this.context = context1;
this.inflater = LayoutInflater.from(context);

}

private CheckBox quanxuan;

public void setQuanxuan(CheckBox quanxuan) {
    this.quanxuan = quanxuan;
}

private CheckBox fuclick;

private List<GouWuChBean.DataBean> listBeans;
public void setFuclick(CheckBox fuclick,List<GouWuChBean.DataBean> beanList) {
this.listBeans=beanList;
this.fuclick = fuclick;
}

@NonNull
@Override
public BBA onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = inflater.inflate(R.layout.zilayout, viewGroup, false);
    BBA bba = new BBA(view);
    return bba;
}

@Override
public void onBindViewHolder(@NonNull BBA bba, final int i) {
    String price = list.get(i).getPrice();
    bba.zijiage.setText("¥" + price);
    String title = list.get(i).getTitle();
    bba.ziname.setText(title);
    Uri uri = Uri.parse(list.get(i).getImages());
    bba.ziimg.setImageURI(uri);
    boolean click = list.get(i).isClick();
    bba.ziclick.setChecked(click);
    bba.ziclick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CheckBox box= (CheckBox) v;
            boolean checked = box.isChecked();
            list.get(i).setClick(checked);
            boolean fuclicks = fuclicks();
            fuclick.setChecked(fuclicks);
            boolean quanxuans = quanxuans();
            quanxuan.setChecked(quanxuans);
            zongJiaintenter.zong();
            notifyDataSetChanged();
        }


});
}
private boolean quanxuans(){
    for (int i = 0; i <listBeans.size(); i++) {
        List<GouWuChBean.DataBean.ListBean> list = listBeans.get(i).getList();
        for (int j = 0; j < list.size(); j++) {
            boolean click = list.get(j).isClick();
            if (!click) {
                return false;
            }
        }
    }
    return true;
}
private boolean fuclicks() {
    for (int i = 0; i < list.size(); i++) {
        boolean click = list.get(i).isClick();
        if (!click) {
            return false;
        }
    }
    return true;
}
@Override
public int getItemCount() {
    return list.size();
}

List<GouWuChBean.DataBean.ListBean> list = new ArrayList<>();

public void setData(List<GouWuChBean.DataBean.ListBean> lists) {
    this.list.clear();
    this.list.addAll(lists);
    notifyDataSetChanged();
}

public class BBA extends RecyclerView.ViewHolder {

    private final TextView zijiage;
    private final TextView ziname;
    private final SimpleDraweeView ziimg;
    private final CheckBox ziclick;

    public BBA(@NonNull View itemView) {
        super(itemView);
        zijiage = itemView.findViewById(R.id.zijiage);
        ziname = itemView.findViewById(R.id.ziname);
        ziimg = itemView.findViewById(R.id.ziSimpleDraweeView);
        ziclick = itemView.findViewById(R.id.zi);
    }
}

}

全选接口

public interface ZongJiaintenter {
void zong();
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值