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

import java.util.List;

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.cpzslibs.prot.handset.bean.res.FarmerBean;

public class FarmerListAdapter extends BaseAdapter {
	public static interface IOnItemSelectListener {
		public void onItemClick(int pos);
	};

	private List<FarmerBean> datas;


	public FarmerListAdapter(List<FarmerBean> datas) {
		this.datas = datas;
	}

	public void refreshData(List<FarmerBean> objects, int selIndex) {
		datas = objects;
		if (selIndex < 0) {
			selIndex = 0;
		}
		if (selIndex >= datas.size()) {
			selIndex = datas.size() - 1;
		}
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {

		return datas.size();
	}

	@Override
	public Object getItem(int pos) {
		return datas.get(pos).toString();
	}

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

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;

		if (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spiner_item_text_layout, parent,false);
			viewHolder = new ViewHolder();
			viewHolder.mTextView = (TextView) convertView.findViewById(R.id.tv_spinner_item);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.mTextView.setText(datas.get(pos).getName()+"");

		return convertView;
	}

	public static class ViewHolder {
		public TextView mTextView;
	}
	
	
}
