Code the Activity

You are almost ready to test your custom adapter. But first you need to change the ContactListActivity code to retrieve contact objects rather than contact names, set the ListView to use the custom adapter, and code the onItemClick method to pass the selected contact’s ID to ContactActivity. The first two changes require changing only one line of code each. Switch to the ContactListActivity.java. Code the activity to retrieve Contact objects rather than names by changing the

ArrayList<String> names = ds.getContactName();

line of code to

final ArrayList<Contact> contacts = ds.getContacts();

The final keyword needs to be added because you will now use the ArrayList inside ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.