package com.example.administrator.zhapp.adapter;

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.example.administrator.zhapp.R;
import com.example.administrator.zhapp.entity.XfsInfo;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * 消防栓适配器
 */
public class XfsAdapter extends BaseAdapter {

    private Context context;
    private List<XfsInfo> list;

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

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

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

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

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

        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.xfxc_item, viewGroup,false);
            holder.tv_xh = (TextView) view.findViewById(R.id.tv_xh);
            holder.tv_bw = (TextView) view.findViewById(R.id.tv_bw);
            holder.tv_bh = (TextView) view.findViewById(R.id.tv_bh);
            holder.tv_zt = (TextView) view.findViewById(R.id.tv_zt);
            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        XfsInfo info = getItem(i);
        holder.tv_xh.setText(info.getItme());
        holder.tv_bh.setText(info.getNum());
        holder.tv_bw.setText(info.getPlace());
        if (info.isState()) {
            holder.tv_zt.setText("已检");
        } else {
            holder.tv_zt.setText("未检");
        }
        return view;
    }

    static class ViewHolder {
        TextView tv_xh;
        TextView tv_bh;
        TextView tv_bw;
        TextView tv_zt;
    }
}
