duobuju

public class Myadapter extends RecyclerView.Adapter{

    private Context context;
    private List<bean1> list;

    public Myadapter(Context context, List<bean1> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = null;
        RecyclerView.ViewHolder holder = null;
        switch (viewType){


            case 0:
                view = View.inflate(context,R.layout.item1,null);
                holder = new ViewHloder1(view);
                break;
            case 1:
                view = View.inflate(context,R.layout.item2,null);
                holder = new ViewHloder2(view);
                break;
        }

        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {


        switch (getItemViewType(position)){

            case 0:
                ViewHloder1 viewHloder1 = (ViewHloder1) holder;
                String images = list.get(position).images;String[] split = images.split("\\|");
                Glide.with(context).load(split[0]).into(viewHloder1.te_img1);
                viewHloder1.te_title1.setText(list.get(position).title);
                viewHloder1.te_jia1.setText(list.get(position).bargainPrice+"");
                System.out.println("++++++++++"+list.get(position).title);
                break;
            case 1:
                ViewHloder2 viewHloder2 = (ViewHloder2) holder;
                String images1 = list.get(position).images;
                String[] split1 = images1.split("\\|");
                Glide.with(context).load(split1[0]).into(viewHloder2.te_img2);
                viewHloder2.te_title2.setText(list.get(position).title);
                viewHloder2.te_jia2.setText(list.get(position).bargainPrice+"");
                Glide.with(context).load(split1[0]).into(viewHloder2.te_img3);
                viewHloder2.te_title3.setText(list.get(position).title);
                viewHloder2.te_jia3.setText(list.get(position).bargainPrice+"");
                break;


        }


    }

    @Override
    public int getItemViewType(int position) {
        if(position%2==0)
        {

            return 0;
        }else
        {

            return 1;

        }
    }

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

    public class ViewHloder1 extends RecyclerView.ViewHolder{


        private final TextView te_title1;
        private final ImageView te_img1;
        private final TextView te_jia1;

        public ViewHloder1(View itemView) {
            super(itemView);

            te_title1 = itemView.findViewById(R.id.te_title1);
            te_img1 = itemView.findViewById(R.id.te_img1);
            te_jia1 = itemView.findViewById(R.id.te_jia1);

        }
    }

    public class ViewHloder2 extends RecyclerView.ViewHolder{


        private final TextView te_title2;
        private final ImageView te_img2;
        private final TextView te_jia2;
        private final TextView te_title3;
        private final ImageView te_img3;
        private final TextView te_jia3;

        public ViewHloder2(View itemView) {
            super(itemView);

            te_title2 = itemView.findViewById(R.id.te_title2);
            te_img2 = itemView.findViewById(R.id.te_img2);
            te_jia2 = itemView.findViewById(R.id.te_jia2);
            te_title3 = itemView.findViewById(R.id.te_title3);
            te_img3 = itemView.findViewById(R.id.te_img3);
            te_jia3 = itemView.findViewById(R.id.te_jia3);

        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值