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

Sort the Contacts List

The next task is to code the ContactListActivity to sort the contact list according to the preferences set by the user. The first step is to modify the getContacts method in ContactDataSource. The method needs to be modified to accept the sort field and sort order as parameters and use these parameters in the SQL to perform the actual sort. Switch to ContactDataSource.java and locate the getContacts method. Change the message signature from

public ArrayList<Contact> getContacts() {

to

public ArrayList<Contact> getContacts(String sortField, String sortOrder) {

Next, change the SQL statement from

String query = "SELECT * FROM contact ...

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