Code the Activity

After the layout is complete, open ContactListActivity.java. Add code to make the navigation buttons work. Be sure to disable the List button (see “Code the Page’s Behavior” in Chapter 5). Next, change the class declaration line of code so that it extends ListActivity rather than Activity, as shown next:

public class ContactListActivity extends ListActivity {

You will have to import ListActivity. Next, enter the code in Listing 6.3 in the onCreate method after the calls to the button initialization methods.

Listing 6.3 Simple List Activation Code

ContactDataSource ds = new ContactDataSource(this);ds.open();ArrayList<String> names = ds.getContactName();ds.close();

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.