MyCertificationRecAdapter.java 1.8 KB
package com.hh.xuetubao.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.hh.xuetubao.R;
import com.hh.xuetubao.bean.CertListBean;

import java.util.List;

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

    private List<CertListBean.BeanCertList> list;
    private Context context;

    public MyCertificationRecAdapter(List<CertListBean.BeanCertList> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.rv_mycertification, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (list.get(position).getCertName() != null)
            holder.title.setText(list.get(position).getCertName());
        if (list.get(position).getCoverPicUrl() != null)
            Glide.with(context).load(list.get(position).getCoverPicUrl()).into(holder.img);
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView title;
        private final ImageView img;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tv_title);
            img = (ImageView) itemView.findViewById(R.id.img);
        }
    }
}