package it.unipr.mobdev;

import it.unipr.dsg.mobdev.R;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class BookmarkListAdapter extends ArrayAdapter<BookmarkDescriptor>{

	private Context mContext = null;
	private List<BookmarkDescriptor> bookmarkList = null;

	public BookmarkListAdapter(Context context, 
			int textViewResourceId, List<BookmarkDescriptor> objects) {
		super(context,textViewResourceId);
		this.mContext  = context;
		this.bookmarkList  = objects;
	}

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

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		if (v == null) {
			LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.custom_list_element, null);
		}
		
		TextView bookmarkTextView = (TextView)v.findViewById(R.id.bookmarkElementTextView);
		bookmarkTextView.setText(this.bookmarkList.get(position).getName());
		
		return v;
	}
	
}
