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

public class ProductGvAdapter extends BaseAdapter{
	private List<Product> products;
	
	public ProductGvAdapter(List<Product> products) {
		this.products = products;
	}
	
	public void refreshData(List<Product> products){
		this.products = products;
		notifyDataSetChanged();
	}

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

	@Override
	public Object getItem(int position) {
		return products.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.adapter_product_gv_item, parent, false);
			holder = new ViewHolder();
			holder.tv_product_lv_item_name = (TextView) convertView.findViewById(R.id.tv_product_lv_item_name);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Product p = products.get(position);
		holder.tv_product_lv_item_name.setText(p.getName()+"");
		
		return convertView;
	}
	
	private class ViewHolder{
		TextView tv_product_lv_item_name;
	}

}
