O'Reilly logo

Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android by Michael Eierman, Jakob Iversen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create the Data Source Method

The complex list displays and uses several bits of data about a contact. To function properly, it needs all the data for a contact. This requires a method to retrieve contact data for all contacts from the database. Open or switch to ContactDataSource.java to create a new method that returns that data as Contact objects in an ArrayList. Use the code in Listing 6.5.

Listing 6.5 getContacts Method

public ArrayList<Contact> getContacts() {    ArrayList<Contact> contacts = new ArrayList<Contact>();    try {        String query = "SELECT  * FROM contact";        Cursor cursor = database.rawQuery(query, null);        Contact newContact;        cursor.moveToFirst();        while (!cursor.isAfterLast()) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required