package com.handstudio.android.adapter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import com.handstudio.android.loooky.R;
import com.handstudio.android.utils.ViewHolder;
import com.handstudio.android.vo.Contact;
import android.content.Context;
import android.content.DialogInterface;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
public class ContactAdapter extends BaseAdapter {
private int layout;
private Context context;
private LayoutInflater inflater;
private ArrayList<Contact> contactList;
private SparseArray<WeakReference<View>> viewArray;
public ContactAdapter(Context context , int layout , ArrayList<Contact> contactList){
this.context = context;
this.layout = layout;
this.contactList = contactList;
this.viewArray = new SparseArray<WeakReference<View>>(contactList.size());
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return contactList.size();
}
@Override
public Object getItem(int position) {
return contactList.get(position).getName();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (viewArray != null && viewArray.get(position) != null) {
convertView = viewArray.get(position).get();
if (convertView != null)
return convertView;
}
if (convertView == null) {
convertView = inflater.inflate(layout, parent, false);
}
Button btnCall = ViewHolder.get(convertView ,R.id.btnCall);
TextView txtContactName = ViewHolder.get(convertView ,R.id.txtContactName);
btnCall.setTag(position);
btnCall.setOnClickListener(mOnClickListener);
txtContactName.setText(contactList.get(position).getName());
System.out.println(" contactList.get(position) : " + contactList.get(position).getPhoneNumber());
return convertView;
}
Button.OnClickListener mOnClickListener = new Button.OnClickListener() {
@Override
public void onClick(View v) {
int position = Integer.parseInt( (v.getTag().toString()) );
System.out.println("contactList.get(position).getPhoneNumber() : " + contactList.get(position).getPhoneNumber());
}
};
}
|