多条目

package com.example.mvptext.view.adapter;


import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.mvptext.R;
import com.example.mvptext.model.JsenBean;

import java.util.List;

/**
 * @Auther: 白俊岭
 * @Date: 2019/3/17 11:08:45
 * @Description:
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.Viewholder> {
    Context context;
    List<JsenBean.DataBeanX.DataBean> jsenBean;
    List<String> pics;
    public MyAdapter(Context context, List<JsenBean.DataBeanX.DataBean> jsenBean, List<String> pics) {
        this.context = context;
        this.jsenBean = jsenBean;
        this.pics=pics;
    }


    @Override
    public int getItemViewType(int position) {
        return position%2;
    }

    @NonNull
    @Override
    public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
    {
        View view = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
        Viewholder viewholder = new Viewholder(view);
        return viewholder;
    }

    @Override
    public void onBindViewHolder(@NonNull Viewholder holder, int position)
    {
        int type = getItemViewType(position);
        switch (type)
        {
            case 0:
                holder.name.setText(jsenBean.get(position).getTitle());
                Glide.with(context)
                        .load(pics.get(0))
                        .into(holder.img);



                break;
            case 1:
                holder.name1.setText(jsenBean.get(position).getTitle());
                Glide.with(context)
                        .load(jsenBean.get(position).getPic_amount())
                        .into(holder.img1);
                break;
        }


    }


    @Override
    public int getItemCount() {


        return jsenBean.size();

    }

    public class Viewholder extends RecyclerView.ViewHolder {

         ImageView img;
       TextView name;
        ImageView img1;
        TextView name1;

        public Viewholder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            name = itemView.findViewById(R.id.name);
            img1 = itemView.findViewById(R.id.img1);
            name1 = itemView.findViewById(R.id.name1);

        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值