其他分享
首页 > 其他分享> > 子Adapter

子Adapter

作者:互联网

public class RxxpAdapter extends RecyclerView.Adapter<RxxpAdapter.ViewHolder> {

RecyBean.ResultBean.RxxpBean rxxpBean;
Context context;

public RxxpAdapter(RecyBean.ResultBean.RxxpBean rxxpBean, Context context) {
    this.rxxpBean = rxxpBean;
    this.context = context;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(context).inflate(R.layout.rxxp_item, viewGroup, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
    RecyBean.ResultBean.RxxpBean.CommodityListBean listBean = rxxpBean.getCommodityList().get(i);
    Glide.with(context).load(listBean.getMasterPic()).into(viewHolder.image);
    viewHolder.text01.setText(listBean.getCommodityName());
    viewHolder.text02.setText("¥:"+listBean.getPrice());
    viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onclick.onclick();
        }
    });
}

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

public class ViewHolder extends RecyclerView.ViewHolder {

    private final ImageView image;
    private final TextView text01,text02;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        image = itemView.findViewById(R.id.image_rxxp);
        text01 = itemView.findViewById(R.id.text01_rxxp);
        text02 = itemView.findViewById(R.id.text02_rxxp);
    }
}
onClick onclick;

public void setOnclick(onClick onclick) {
    this.onclick = onclick;
}

interface onClick{
    void onclick();
}

}

标签:ViewHolder,context,itemView,Adapter,onclick,rxxpBean,public
来源: https://blog.csdn.net/weixin_44668084/article/details/89420190