package com.qhclh.ytzh.work;

import android.content.Context;
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.qhclh.ytzh.R;
import com.qhclh.ytzh.bean.WorkBean;

import java.util.List;

/**
 * Created by 青花瓷 on 2017/12/18.
 */

public class WorkAdapter extends RecyclerView.Adapter<WorkAdapter.MyViewHolder> {
    private Context mContext;
    private List<WorkBean> mList;

    public WorkAdapter(Context mContext, List<WorkBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_work,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        WorkBean workBean = mList.get(position);
        MyViewHolder myViewHolder = holder;

        myViewHolder.getImageView().setImageResource(workBean.getImg());
        myViewHolder.getTextView().setText(workBean.getText());
    }

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

    public List<WorkBean> getmList() {
        return mList;
    }

    @Override
    public long getItemId(int position) {
        return mList.get(position).getId();
    }

    /**
     *将ViewHolder类写成静态的.
     **/
    static class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private TextView textView;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.item_work_iv);
            textView = itemView.findViewById(R.id.item_work_tv);
        }

        public ImageView getImageView() {
            return imageView;
        }

        public TextView getTextView() {
            return textView;
        }
    }
}
