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.LinearLayout;
import android.widget.TextView;


import com.qhclh.ytzh.R;

import java.util.List;

/**
 * Created by 青花瓷 on 2017/6/29.
 */
///< 利润分析中一个适配器
public class LvBuildhousenaneAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;

    public LvBuildhousenaneAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

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

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

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_lv_buildhouse_name, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.ll_buildhousename = convertView.findViewById(R.id.ll_buildhousename);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_name.setText(list.get(position));
        if (position%2==0){
            holder.ll_buildhousename.setBackgroundColor(context.getResources().getColor(R.color.greyf4f4f4));
        }else {
            holder.ll_buildhousename.setBackgroundColor(context.getResources().getColor(R.color.white));
        }
        return convertView;
    }

    class ViewHolder {
        TextView tv_name;
        LinearLayout ll_buildhousename;
    }
}
