package com.example.adapter;

import java.util.ArrayList;
import java.util.List;

import com.example.model.Person;
import com.example.sqlite_examplev2.R;

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

public class CustomArrayAdapter extends ArrayAdapter<Person> {
	private final Activity context;
	private final List<Person> people;

	public CustomArrayAdapter(Activity context, List<Person> people) {
		super(context, R.layout.rowlayout, people);
		this.context = context;
		this.people = people;
	}

	public View getView(int pos, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
		
		// set the view with the object's data
		TextView textView = (TextView) rowView.findViewById(R.id.secondLine);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
		
		textView.setText(people.get(pos).toString());
		imageView.setImageResource(R.drawable.ic_launcher);
		
		return rowView;
	}
}

@@ -779,116 +779,168 @@
 %7B%0A%09%09
-LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);%0A%09%09View 
+View rowView = convertView;%0A%0A%09%09TextView textView;%0A%09%09ImageView imageView;%0A%0A%09%09if (rowView == null) %7B%0A%09%09%09LayoutInflater inflater = context.getLayoutInflater();%0A%09%09%09
 rowV
@@ -1004,61 +1004,37 @@
 ;%0A%09%09
+%7D%0A
 %0A%09%09// 
-set the view with the object's data%0A%09%09TextView 
+get provided views%0A%09%09
 text
@@ -1088,34 +1088,24 @@
 ondLine);%0A%09%09
-ImageView 
 imageView = 
@@ -1149,18 +1149,54 @@
 .icon);%0A
+%0A
 %09%09
+// set the views with object's data
 %0A%09%09textV
@@ -1290,18 +1290,16 @@
 ncher);%0A
-%09%09
 %0A%09%09retur

implement performance optimization on custom array adapter