Create the Data Source Method

The first step to implementing the simple list is to have data. For this, you need to add a method to the ContactDataSource class that will retrieve each contact’s name. Open ContactDataSource.java and add the code in Listing 6.1 to create a method for getting this data from the database.

Listing 6.1 getContactName Code

public ArrayList<String> getContactName() {    ArrayList<String> contactNames = new ArrayList<String>();                     //1    try {        String query = "Select contactname from contact";                         //2        Cursor cursor = database.rawQuery(query, null);        cursor.moveToFirst();                                                     //3         ...

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.