Android SQLite Sort order does not work with upper and lowercase letters

If you are using SQLite database, with a Cursor or Perhaps Content provider, you may have come across alphabetical sorting problems regarding upper and lowercase letters.

Perhaps you are requesting a cursor from a Content Provider:

String[] projection = { Table.COLUMN_ID, Table.COLUMN_TITLE};

String sortOrder = Table.COLUMN_TITLE + " COLLATE NOCASE ASC";

CursorLoader cursorLoader = new CursorLoader(this,  
    YourProvider.CONTENT_URI,
    projection,
    null,
    null,
    sortOrder);

The solution to the alphabetical sorting problem is the COLLATE NOCASE in the part of the query where you specify the sorting.

Note that the ASC is optional to specify. You could also use DESC to reverse the sorting order. You can find more information on CursorLoader at the Android Developer site, here and here.

comments powered by Disqus