package com.example.contactslist;

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

public class ListAdapter extends BaseAdapter {
	private String[] _data;
	Context _c;

	ListAdapter(String[] data, Context c) {
		_data = data;
		_c = c;
	}

	public int getCount() {
		return _data.length;
	}

	public Object getItem(int position) {
		return _data[position];
	}

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

	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) _c
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.list_items, null);
		}
		TextView contact = (TextView) v.findViewById(R.id.listItem);
		String name = _data[position];

		contact.setText(name);

		return v;
	}
}
