package com.example.aason.gouwuche1.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.aason.gouwuche1.R;
import com.example.aason.gouwuche1.bean.CartBean;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.ArrayList;
import java.util.List;
public class ProdAdapter extends XRecyclerView.Adapter<ProdAdapter.MyVh> {
private Context context;
private List<CartBean.DataBean> list;
int a;
public ProdAdapter(Context context, List<CartBean.DataBean> list, int a) {
this.context = context;
this.list = list;
this.a = a;
}
public void setList(List<CartBean.DataBean> list) {
this.list = list;
notifyDataSetChanged();
}
@NonNull
@Override
public MyVh onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(context).inflate(R.layout.item1,viewGroup,false);
return new MyVh(view);
}
@Override
public void onBindViewHolder(@NonNull MyVh myVh, int i) {
List<CartBean.DataBean.SpusBean> spus = list.get(a).getSpus();
myVh.checkbox.setChecked(spus.get(i).isProductChecked);
myVh.price.setText("¥:" +spus.get(i).getPraise_num()+"");
myVh.title.setText(spus.get(i).getName());
Glide.with(context).load(spus.get(i).getPic_url()).into(myVh.img);
}
@Override
public int getItemCount() {
return list.get(a).getSpus().size();
}
public class MyVh extends RecyclerView.ViewHolder {
private final CheckBox checkbox;
private final TextView title;
private final TextView price;
private final ImageView img;
public MyVh(@NonNull View itemView) {
super(itemView);
checkbox = itemView.findViewById(R.id.checkbox);
title = itemView.findViewById(R.id.title);
price = itemView.findViewById(R.id.price);
img = itemView.findViewById(R.id.img);
}
}
}