You should create a custom adapter that extends the ArrayAdapter . Everything you can do with the ArrayAdapter is limited.
Something like that:
public class PersonAdapter extends ArrayAdapter<Person> { private final Context context; private final ArrayList<Person> data; private final int layoutResourceId; public PersonAdapter(Context context, int layoutResourceId, ArrayList<Person> data) { super(context, layoutResourceId, data); this.context = context; this.data = data; this.layoutResourceId = layoutResourceId; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; ViewHolder holder = null; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new ViewHolder(); holder.textView1 = (TextView)row.findViewById(R.id.text1); holder.textView2 = (TextView)row.findViewById(R.id.text2); ... ... holder.textView3 = (TextView)row.findViewById(R.id.text3); row.setTag(holder); } else { holder = (ViewHolder)row.getTag(); } Person person = data.get(position); holder.textView1.setText(person.getName()); holder.textView2.setText(person.getAddress()); ... ... holder.textView3.setText(person.getEtc()); return row; } static class ViewHolder { TextView textView1; TextView textView2; ... ... TextView textView3; } }
Where textView1 , textView2 ... textView-n are all your text views. Install the adapter as follows:
setListAdapter(new PersonAdapter(MyActivity.this, R.layout.list_text, personList));
Note. I assume that your personList is an object of type List . If it's Array , let me know.
Amulya khare
source share