package com.training.listviewsample4;

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

import java.util.ArrayList;

public class ContactsAdapter extends BaseAdapter {
    ArrayList<Contact> contacts;
    LayoutInflater layoutInflater;

    public ContactsAdapter(Context context, ArrayList<Contact> contacts){
        layoutInflater = LayoutInflater.from(context);
        this.contacts = contacts;

    }

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

    @Override
    public Object getItem(int position) {
        return contacts.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder viewHolder = null;

        if(convertView == null) {
            view = layoutInflater.inflate(R.layout.row, parent, false);

            viewHolder = new ViewHolder();
            viewHolder.picture = (ImageView) view.findViewById(R.id.picture);
            viewHolder.name = (TextView) view.findViewById(R.id.name);

            view.setTag(viewHolder);

        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();

        }

        Contact contact = (Contact) getItem(position);
        viewHolder.picture.setImageResource(contact.pictureId);
        viewHolder.name.setText(contact.name);

        return view;

    }

    public void addContact(Contact contact) {
        contacts.add(contact);
        notifyDataSetChanged();

    }

    static class ViewHolder {
        ImageView picture;
        TextView name;

    }

}

@@ -479,18 +479,19 @@
 ontacts)
+ 
 %7B%0A
-
         
@@ -1015,16 +1015,17 @@
       if
+ 
 (convert
@@ -1617,32 +1617,32 @@
 contact.name);%0A%0A
+
         return v
@@ -1658,125 +1658,8 @@
  %7D%0A%0A
-    public void addContact(Contact contact) %7B%0A        contacts.add(contact);%0A        notifyDataSetChanged();%0A%0A    %7D%0A%0A
     

clean unused code