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.ImageView;
import android.widget.TextView;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.common.config.HandsetOperation;

public class HomeAdapter extends BaseAdapter{
	private List<HandsetOperation> homeBeans;
	
	public HomeAdapter(List<HandsetOperation> homeBeans) {
		this.homeBeans = homeBeans;
	}
	
	public void refreshData(List<HandsetOperation> homeBeans){
		this.homeBeans = homeBeans;
		notifyDataSetChanged();
	}

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

	@Override
	public Object getItem(int position) {
		return homeBeans.get(position);
	}

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

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.gv_home_item, parent, false);
			holder = new ViewHolder();
			holder.image_main_icon = (ImageView) convertView.findViewById(R.id.image_main_icon);
			holder.tv_main_name = (TextView) convertView.findViewById(R.id.tv_main_name);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.image_main_icon.setImageResource(homeBeans.get(position).getResId());
		holder.tv_main_name.setText(homeBeans.get(position).getOptionName());
		
		return convertView;
	}
	
	private class ViewHolder{
		private ImageView image_main_icon;
		private TextView tv_main_name;
	}

}
