Reputation: 1196
I am trying to extract a list of contacts from Android, the list returns correctly. The returned list is sorted in alphabetical order however the upper case letters are first followed by the lower case characters. Example. ABCDEFGHIJ.....abcdef
The following is the cursor I am using:
Cursor cursor = contentResolver.query(CONTENT_URI, null,null, null, "display_name ASC");
Upvotes: 1
Views: 1043
Reputation: 761
Use My code
private void getContactList() {
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null,
"display_name COLLATE NOCASE ASC");
if (cursor != null) {
HashSet<String> mobileNoSet = new HashSet<String>();
try {
final int nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String name, number;
while (cursor.moveToNext()) {
name = cursor.getString(nameIndex);
number = cursor.getString(numberIndex);
number = number.replace(" ", "");
if (!mobileNoSet.contains(number)) {
contactList.add(new Contact(name, number));
mobileNoSet.add(number);
}
}
} finally {
cursor.close();
}
}
}
Upvotes: 0
Reputation: 643
use display_name COLLATE NOCASE ASC to order the record case insensitive.
Upvotes: 4