package com.qhclh.ytzh.work.scan;

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

import java.util.List;

/**
 * Created by 青花瓷 on 2017/11/30.
 */
///< 扫一扫雏苗
public class ScanAdapter extends BaseAdapter {

    private Context context;
    private List<ScanBean> list;
    private LayoutInflater layoutInflater;

    public ScanAdapter(Context context, List<ScanBean> 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;
        ScanBean message = list.get(i);
        if (view == null){
            view = layoutInflater.inflate(R.layout.item_infos,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.infos_carname = view.findViewById(R.id.infos_carname);
            viewHolder.infos_driver = view.findViewById(R.id.infos_driver);
            viewHolder.infos_phone = view.findViewById(R.id.infos_phone);
            viewHolder.infos_fuhuachang = view.findViewById(R.id.infos_fuhuachang);
            viewHolder.infos_leavetime = view.findViewById(R.id.infos_leavetime);
            viewHolder.infos_yangzhichang = view.findViewById(R.id.infos_yangzhichang);
            viewHolder.infos_daodashijian = view.findViewById(R.id.infos_daodashijian);


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

        viewHolder.infos_carname.setText(message.getInfos_carname());
        viewHolder.infos_driver.setText(message.getInfos_driver());
        viewHolder.infos_phone.setText(message.getInfos_phone());
        viewHolder.infos_fuhuachang.setText(message.getInfos_fuhuachang());
        viewHolder.infos_leavetime.setText(message.getInfos_leavetime());
        viewHolder.infos_yangzhichang.setText(message.getInfos_yangzhichang());
        viewHolder.infos_daodashijian.setText(message.getInfos_daodashijian());


        return view;
    }

    private class ViewHolder{
        private TextView infos_carname;
        private TextView infos_driver;
        private TextView infos_phone;
        private TextView infos_fuhuachang;
        private TextView infos_leavetime;
        private TextView infos_yangzhichang;
        private TextView infos_daodashijian;
    }
}
