package com.qhclh.ytzh.index.shangpin;

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.ShangpinPianquBean;

import java.util.List;

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

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

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

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

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ShangpinPianquBean shangpinPianquBean = mList.get(position);
        MyViewHolder myViewHolder = holder;
        myViewHolder.getShangpinpianqu_name().setText(shangpinPianquBean.getPianqu());
        myViewHolder.getShangpinpianqu_zonglan().setText(shangpinPianquBean.getZonglan());
        myViewHolder.getShangpinpianqu_cunlan().setText(shangpinPianquBean.getCunlan());
        myViewHolder.getShangpinpianqu_konglan().setText(shangpinPianquBean.getKonglan());

    }

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

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

    /**
     *将ViewHolder类写成静态的.
     **/
    static class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView shangpinpianqu_name;
        private TextView shangpinpianqu_zonglan;
        private TextView shangpinpianqu_cunlan;
        private TextView shangpinpianqu_konglan;
        public MyViewHolder(View itemView) {
            super(itemView);
            shangpinpianqu_name = itemView.findViewById(R.id.shangpinpianqu_name);
            shangpinpianqu_zonglan = itemView.findViewById(R.id.shangpinpianqu_zonglan);
            shangpinpianqu_cunlan = itemView.findViewById(R.id.shangpinpianqu_cunlan);
            shangpinpianqu_konglan = itemView.findViewById(R.id.shangpinpianqu_konglan);
        }

        public TextView getShangpinpianqu_name() {
            return shangpinpianqu_name;
        }

        public TextView getShangpinpianqu_zonglan() {
            return shangpinpianqu_zonglan;
        }

        public TextView getShangpinpianqu_cunlan() {
            return shangpinpianqu_cunlan;
        }

        public TextView getShangpinpianqu_konglan() {
            return shangpinpianqu_konglan;
        }
    }
}
