views:

448

answers:

2
private Cursor getContacts()
    {
        // Run query
        Uri uri = ContactsContract.Contacts.CONTENT_URI;
        String[] projection = new String[] {
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME
        };
        String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
                (mShowInvisible ? "0" : "1") + "'";
        String[] selectionArgs = null;
        String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

        return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
    }

What does COLLATE LOCALIZED ASC stand for?

+4  A: 

Collate is just fancy speak for sort (well sort of). So this is sort ordering based on localized preferences (i.e. current language's alphabet and conventions) in ascending order.

Kris
Do I have to define anything additional to my table schema to be able to use it? Is this SQLite specific or just Android specific? Can I sort by these all my custom columns?
Pentium10
+2  A: 

COLLATE is an SQL operator that lets you override the default sort order for strings. For example, "COLLATE NOCASE" does case-insensitive comparison, and "COLLATE BINARY" does a case-sensitive comparison.

The SQLite C interface lets you define custom collations (http://www.sqlite.org/c3ref/create_collation.html).

dan04