package com.qhclh.ytzh.work.tablepoultry;

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

import java.util.List;

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

public class XFactryAdapter extends BaseAdapter{
    private Context context;
    private List<TablePBean> list;
    private LayoutInflater layoutInflater;

    public XFactryAdapter(Context context, List<TablePBean> 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;
        TablePBean message = list.get(i);

        if (view == null){
            view = layoutInflater.inflate(R.layout.item_tablep,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.tab_breedFactory_name = view.findViewById(R.id.tab_breedFactory_name);
            viewHolder.tab_days = view.findViewById(R.id.tab_days);
            viewHolder.tab_dienub = view.findViewById(R.id.tab_dienub);
            viewHolder.tab_obs = view.findViewById(R.id.tab_obs);


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

        viewHolder.tab_breedFactory_name.setText("厂:"+message.getBreedFactory_name());
        viewHolder.tab_days.setText("日龄:"+message.getDays());
        viewHolder.tab_dienub.setText("死亡:"+message.getDienumber());
        viewHolder.tab_obs.setText("淘汰:"+message.getObs());

        return view;
    }

    private class ViewHolder {
        private TextView tab_breedFactory_name;
        private TextView tab_days;
        private TextView tab_dienub;
        private TextView tab_obs;

    }
}
