package com.zhn.tongxunlu;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ContactAdapter extends BaseAdapter {

	private Context context;
	private List<Contact> contacts;
	private LayoutInflater inflater;
	

	public ContactAdapter(Context context, List<Contact> contacts,
			ListView listView) {
		this.context = context;
		this.contacts = contacts;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contacts.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return contacts.get(position);
	}

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

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_adapter, null);
			holder = new ViewHolder();
			holder.per_icon = (ImageView) convertView
					.findViewById(R.id.per_icon);
			holder.per_name = (TextView) convertView
					.findViewById(R.id.per_name);
			holder.per_num = (TextView) convertView
					.findViewById(R.id.per_number);
			holder.per_edit = (ImageView) convertView
					.findViewById(R.id.per_edit);
			convertView.setTag(holder);
		}
		holder = (ViewHolder) convertView.getTag();
		Contact contact = contacts.get(position);
		holder.per_icon.setImageResource(R.drawable.preson_icon);
		holder.per_name.setText(contact.getName());
		holder.per_num.setText(contact.getPhone());
		return convertView;
	}
}

class ViewHolder {
	ImageView per_icon;
	TextView per_name;
	TextView per_num;
	ImageView per_edit;
}
