package com.qhclh.ytzh.index.fumudai;

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 com.qhclh.ytzh.bean.ThreeTypeBean;

import java.util.List;

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

public class ThreeTypeAdapter extends BaseAdapter {
    private Context context;
    private List<ThreeTypeBean> list;
    private LayoutInflater layoutInflater;

    public ThreeTypeAdapter(Context context, List<ThreeTypeBean> 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).getYangzhichangid();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder;
        ThreeTypeBean message = list.get(i);
        if (view == null){
            view = layoutInflater.inflate(R.layout.item_threetype,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.item_three_yangzhichang = view.findViewById(R.id.item_three_yangzhichang);
            viewHolder.item_three_item1 = view.findViewById(R.id.item_three_item1);
            viewHolder.item_three_item2 = view.findViewById(R.id.item_three_item2);
            viewHolder.item_three_ll = view.findViewById(R.id.item_three_ll);

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

        if (i%2==0){
            viewHolder.item_three_ll.setBackgroundColor(context.getResources().getColor(R.color.greyf4f4f4));
        }else {
            viewHolder.item_three_ll.setBackgroundColor(context.getResources().getColor(R.color.white));
        }
        viewHolder.item_three_yangzhichang.setText(message.getYangzhichangname());
        viewHolder.item_three_item1.setText(message.getFirstitem());
        viewHolder.item_three_item2.setText(message.getSeconditem());


        return view;
    }


    private class ViewHolder{
        private TextView item_three_yangzhichang;
        private TextView item_three_item1;
        private TextView item_three_item2;
        private LinearLayout item_three_ll;
    }
}
