package com.qhclh.ytzh.work.weighingsingle;

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

import com.qhclh.ytzh.R;

import java.util.List;

/**
 * Created by 青花瓷 on 2018/3/12.
 */

public class WeightlistAdapter extends BaseAdapter {
    private Context context;
    private List<WeightBean> list;
    private LayoutInflater layoutInflater;

    public WeightlistAdapter(Context context, List<WeightBean> 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;
        WeightBean message = list.get(i);
        if (view == null){
            view = layoutInflater.inflate(R.layout.item_weightlist,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.item_weight_item1 = view.findViewById(R.id.item_weight_item1);
            viewHolder.item_weight_item2 = view.findViewById(R.id.item_weight_item2);
            viewHolder.item_weight_item3 = view.findViewById(R.id.item_weight_item3);
            viewHolder.item_weight_all = view.findViewById(R.id.item_weight_all);

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

        if (i%2==0){
            viewHolder.item_weight_all.setBackgroundColor(context.getResources().getColor(R.color.greyf4f4f4));
        }else {
            viewHolder.item_weight_all.setBackgroundColor(context.getResources().getColor(R.color.white));
        }
        viewHolder.item_weight_item1.setText("单号:"+message.getID());
        viewHolder.item_weight_item2.setText("车次:"+message.getCarNumber());
        viewHolder.item_weight_item3.setText(message.getBreedFactory_Name());

        return view;
    }

    private class ViewHolder{
        private TextView item_weight_item1;
        private TextView item_weight_item2;
        private TextView item_weight_item3;
        private LinearLayout item_weight_all;
    }
}
