public class Readapyter extends RecyclerView.Adapter<Readapyter.VVH> {
Context context;
HomeBean.ResultBean resultBean;
LayoutInflater layoutInflater;
private OnItemClickListener mListener;// 声明自定义的接口
public Readapyter(Context context, HomeBean.ResultBean resultBean) {
this.layoutInflater = LayoutInflater.from(context);
this.context = context;
this.resultBean = resultBean;
}
public interface OnItemClickListener {
void onItemClick(View view, int postion);
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener ){
this. mListener=onItemClickListener;
}
@NonNull
@Override
public VVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = layoutInflater.inflate(R.layout.layout1, viewGroup, false);
VVH vvh = new VVH(view);
return vvh;
}
@Override
public void onBindViewHolder(@NonNull VVH vvh, int i) {
switch (i) {
case 0:
List<HomeBean.ResultBean.RxxpBean> rxxp = resultBean.getRxxp();
List<HomeBean.ResultBean.RxxpBean.CommodityListBean> commodityList = rxxp.get(0).getCommodityList();
vvh.text.setText(rxxp.get(0).getName());
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3);
vvh.layout1_recyclerView.setLayoutManager(gridLayoutManager);
Readapter1 readapter1 = new Readapter1(context, commodityList);
vvh.layout1_recyclerView.setAdapter(readapter1);
break;
case 1:
List<HomeBean.ResultBean.MlssBean> mlss = resultBean.getMlss();
vvh.text.setText(mlss.get(0).getName());
List<HomeBean.ResultBean.MlssBean.CommodityListBeanXX> commodityList2 = mlss.get(0).getCommodityList();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
vvh.layout1_recyclerView.setLayoutManager(linearLayoutManager);
Readapter3 readapter3 = new Readapter3(context, commodityList2);
vvh.layout1_recyclerView.setAdapter(readapter3);
break;
case 2:
List<HomeBean.ResultBean.PzshBean> pzsh = resultBean.getPzsh();
vvh.text.setText(pzsh.get(0).getName());
List<HomeBean.ResultBean.PzshBean.CommodityListBeanX> commodityList1 = pzsh.get(0).getCommodityList();
GridLayoutManager gridLayoutManager1 = new GridLayoutManager(context, 2);
vvh.layout1_recyclerView.setLayoutManager(gridLayoutManager1);
Readapter2 readapter2 = new Readapter2(context, commodityList1);
vvh.layout1_recyclerView.setAdapter(readapter2);
break;
}
}
@Override
public int getItemCount() {
return 3;
}
class VVH extends RecyclerView.ViewHolder {
private final RecyclerView layout1_recyclerView;
private final TextView text;
public VVH(@NonNull View itemView) {
super(itemView);
layout1_recyclerView = itemView.findViewById(R.id.layout1_RecyclerView);
text = itemView.findViewById(R.id.layout1_text);
}
}
}