Populating the ContactActivity Screen

You’ve learned how to get a list to respond to the selection of a contact in the list by opening the ContactActivity and passing a contact’s ID value to it. The next step is to get the ContactActivity to use that ID to retrieve the contact’s data and display it.

Open the ContactDataSource.java file and add a method to retrieve a specific contact based on the contact’s ID. Use the code in Listing 6.14 to create the method. This code is essentially the same as the getContacts method, except that it returns a single contact rather than an ArrayList of all the contacts.

Listing 6.14 GetSpecificContact Method

public Contact getSpecificContact(int contactId) {                                //1 ...

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.