package viewbg;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class BrowserItemAdapter extends BaseAdapter{

	private Context context;
	private List<BrowserItem> items=new ArrayList<BrowserItem>();
	
	public BrowserItemAdapter(Context context)
	{
		this.context=context;
	}
	
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return items.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		BrowserTextView btv;
		if(arg1==null)
		{
			btv=new BrowserTextView(context,items.get(arg0));
		}
		else
		{
			btv=(BrowserTextView)arg1;
			btv.setText(items.get(arg0).getText());
			btv.setIcon(items.get(arg0).getIcon());
		}
		return btv;
	}
	
	public void addItem(BrowserItem item)
	{
		items.add(item);
	}
	
	public void setListItems(List<BrowserItem> list)
	{
		items=list;
	}
	
	public boolean areAllItemsSelectable()
	{
		return false;
	}
	
	public boolean isSelectable(int position)
	{
		return items.get(position).isSelectable();
	}

}
