首页的适配器1

在这里插入代码片
```public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {

    private Context context;
    private List<HomeshopsBean> homeshopBeanList;//首页商品集合

    public HomeAdapter(Context context, List<HomeshopsBean> homeshopBeanList) {
        this.context = context;
        this.homeshopBeanList = homeshopBeanList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_home, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //具体的每一件商品
        HomeshopsBean homeshopsBean = homeshopBeanList.get(position);
        //设置数据
        holder.bookname.setText(homeshopsBean.getBookname());
        holder.appearance.setText(homeshopsBean.getAppearance());
        holder.location.setText(homeshopsBean.getLocation());

        String[] images = homeshopsBean.getImages().split(",");
        holder.image.setImageURI(images[0]);
        //点击条目跳转到详情页面
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //发送粘性事件
                EventBus.getDefault().postSticky(homeshopsBean);
                Intent intent = new Intent(context, DetailActivity.class);
                context.startActivity(intent);
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.image)
        SimpleDraweeView image;
        @BindView(R.id.bookname)
        TextView bookname;
        @BindView(R.id.appearance)
        TextView appearance;
        @BindView(R.id.location)
        TextView location;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值