How to specify the sort order for the query to a content provider

Janusz picture Janusz · Dec 29, 2014 · Viewed 14k times · Source

I am trying to load all items from a Sqlite Table in Android and want to order the result.

How do I specify the order for the returned cursor?

I query the ContentProvider through a CursorLoader the following way:

new CursorLoader(context, RepresentativeEntityContentProvider.CONTENT_URI, null, null,
            null, null);

Answer

Roll no1 picture Roll no1 · Dec 29, 2014

try below code change COLUMN_NAME with actual column name on which you wants to sort.

new CursorLoader(context, RepresentativeEntityContentProvider.CONTENT_URI, null, null,
            null, "COLUMN_NAME ASC");