CurriculumScheduleRecAdapter.java 2.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.FreeCourseBean;

import java.util.List;

public class CurriculumScheduleRecAdapter extends RecyclerView.Adapter<CurriculumScheduleRecAdapter.ViewHolder> {
    private List<FreeCourseBean.bean> list;
    private Context context;

    public CurriculumScheduleRecAdapter(List<FreeCourseBean.bean> 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.rc_curriculumschedule, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        if (list.get(position).getLessonName() != null)
            holder.title.setText(list.get(position).getLessonName());
        if (list.get(position).getDifficult() != null)
            holder.nanyi.setText(list.get(position).getDifficult());
        if (list.get(position).getLearningPeopleCount() != null)
            holder.count.setText(list.get(position).getLearningPeopleCount());
        if (list.get(position).getLessonCoverPic() != null)
            Glide.with(context).load(list.get(position).getLessonCoverPic()).into(holder.img);


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (turn != null) {
                    turn.turnToDetail(list.get(position).getLessonOid());
                }
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final ImageView img;
        private final TextView title;
        private final TextView nanyi;
        private final TextView count;

        public ViewHolder(View itemView) {
            super(itemView);
            img = (ImageView) itemView.findViewById(R.id.img);
            title = (TextView) itemView.findViewById(R.id.title);
            nanyi = (TextView) itemView.findViewById(R.id.tv_nanyi);
            count = (TextView) itemView.findViewById(R.id.tv_count);

        }
    }

    private Turn turn;

    public void setTurn(Turn turn) {
        this.turn = turn;
    }

    public interface Turn {
        void turnToDetail(String lessonOid);
    }
}