Tuesday, November 10, 2015

Sorting when querying



When doing a query in Android the default sorting is to list Capital letters from A-Z first then lower-case letters a-z.

To sort the list alphabetically regardless of the case of the first letter, you need to do the following.


Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
   ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1", 
   null, 
   "UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ") ASC");
 
 
 
Reference
http://stackoverflow.com/a/24489525