Search code examples
androidandroid-contentproviderandroid-contactsandroid-contentresolver

Android : Contact List is not by all case of Letters


I am trying to fetch all Contact list in a sorting order. I am getting all the contact list but its first sort name starts with Upper case (ABCD..), After sorting all the name starts with Upper case letter then only it start to sort remaining name that starts with Lower case letter (a,b,c....)

private static final String[] PROJECTION = new String[] {
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Phone.NUMBER
};

ContentResolver cr = getContentResolver();
    Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION,
      null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");

if (cursor != null) {
        try {
            final int nameIndex = 
                     cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
                   nameContact = cursor.getString(nameIndex);
    finally {
            cursor.close();
           }

Here the name is sorting as a separate two list. First sort all the name start with Upper Case after that sort name start with Lower Case.

Can any one please tell me how to solve this issue?

Thanks in advance :)


Solution

  • Use the query like this with collate.

    Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION,
      null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE NOCASE ASC");