package com.qhclh.ytzh.index.shangpin;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qhclh.ytzh.R;
import com.qhclh.ytzh.bean.InhouseBean;

import java.util.List;

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

public class InHouseAdapter extends BaseAdapter {
    private Context context;
    private List<InhouseBean> list;
    private LayoutInflater layoutInflater;

    public InHouseAdapter(Context context, List<InhouseBean> list) {
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }

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

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return list.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        InhouseBean message = list.get(i);
        if (view == null){
            view = layoutInflater.inflate(R.layout.item_inhouse,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.inhouse_pici = view.findViewById(R.id.inhouse_pici);
            viewHolder.inhouse_yangzhichang = view.findViewById(R.id.inhouse_yangzhichang);
            viewHolder.inhouse_riqi = view.findViewById(R.id.inhouse_riqi);
            viewHolder.inhouse_zhangtai = view.findViewById(R.id.inhouse_zhangtai);

            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.inhouse_pici.setText("批次："+message.getPici());
        viewHolder.inhouse_yangzhichang.setText("养殖场："+message.getYangzhichang());
        viewHolder.inhouse_riqi.setText("日期："+message.getRiqi());
        viewHolder.inhouse_zhangtai.setText("状态："+message.getZhuangtai());

        return view;
    }


    private class ViewHolder{
        private TextView inhouse_pici;
        private TextView inhouse_yangzhichang;
        private TextView inhouse_riqi;
        private TextView inhouse_zhangtai;
    }
}
