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.caoyao.cpzshandset.bean.StationManagerBean;

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

	private List<StationManagerBean> mObjects;


	public SpinerStationAdapter(List<StationManagerBean> mObjects) {
		this.mObjects = mObjects;
	}

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

	@Override
	public int getCount() {

		return mObjects.size();
	}

	@Override
	public Object getItem(int pos) {
		return mObjects.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_layout, parent,false);
			viewHolder = new ViewHolder();
			viewHolder.mTextView = (TextView) convertView.findViewById(R.id.tv_spinner_item);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		// Object item = getItem(pos);
		viewHolder.mTextView.setText(mObjects.get(pos).getStationname());

		return convertView;
	}

	public static class ViewHolder {
		public TextView mTextView;
	}
}
