package cn.net.caoyao.cpzshandset.ui.adapter;

import java.util.List;

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 cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.bean.CarNoBean;

public class CarNoAdapter extends BaseAdapter{
	private List<CarNoBean> list;
	public CarNoAdapter(List<CarNoBean> list) {
		this.list = list;
	}
	
	public void refreshData(List<CarNoBean> list){
		this.list = list;
		notifyDataSetChanged();
	}

	@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) {
		Context context = parent.getContext();
		ViewHolder holder = null;
		
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.adapter_2_tv_item, parent, false);
			holder = new ViewHolder();
			holder.tv_item1 = (TextView) convertView.findViewById(R.id.tv_item1);
			holder.tv_item2 = (TextView) convertView.findViewById(R.id.tv_item2);
			holder.tv_item3 = (TextView) convertView.findViewById(R.id.tv_item3);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		CarNoBean b = list.get(position);
		
		holder.tv_item1.setText("车  牌  号：" + b.getCarNo());
		holder.tv_item2.setText("配件个数："+b.getNum());
		String date = "";
		if(!"".equals(b.getCarDate())&& null!=b.getCarDate()){
			date = b.getCarDate().substring(0, 10);
		}
		holder.tv_item3.setText("领料日期："+date);//日期一定是一条。且一定有日期
		
		
		return convertView;
	}

	private class ViewHolder{
		TextView tv_item1;
		TextView tv_item2;
		TextView tv_item3;
	}
}
