package com.qhclh.ytzh.index.planorder;

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

import java.util.List;

/**
 * Created by 青花瓷 on 2017/11/29.
 */
///< 派车老板看到的所有车辆
public class CarsAdapter extends BaseAdapter {
    private Context context;
    private List<CarsBean> carsBeen;

    public CarsAdapter(Context context, List<CarsBean> carsBeen) {
        this.context = context;
        this.carsBeen = carsBeen;
    }

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

    @Override
    public Object getItem(int i) {
        return carsBeen.get(i);
    }

    @Override
    public long getItemId(int i) {
        return carsBeen.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        CarsBean message = carsBeen.get(i);
        ViewHolder viewHolder;
        if (view == null){
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_cars,viewGroup,false);
            viewHolder.time = view.findViewById(R.id.cars_time);
            viewHolder.name = view.findViewById(R.id.cars_name);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.name.setText(message.getCarsname());
        viewHolder.time.setText(message.getTime());
        return view;
    }

    private class ViewHolder {
        public TextView time;
        public TextView name;
    }
}
