23

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);
Janusz
  • 187,060
  • 113
  • 301
  • 369
  • 1
    http://stackoverflow.com/questions/20686415/how-to-sort-the-cursorloader-results – Phantômaxx Dec 29 '14 at 09:47
  • additional to accepted answer: its possible to sort for more then one column, e.g. `"column_name1 ASC, column_name2 DESC, column_nameN ASC"` where DESC means descending. – Cor Mar 26 '22 at 11:16

2 Answers2

44

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");
Roll no1
  • 1,315
  • 1
  • 16
  • 23
11
new CursorLoader(context, RepresentativeEntityContentProvider.CONTENT_URI, null, null,
            null, "column_name ASC");

or

new CursorLoader(context, RepresentativeEntityContentProvider.CONTENT_URI, null, null,
                null, "column_name DESC")

;

VikasGoyal
  • 3,308
  • 1
  • 22
  • 42