22

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
  • 182,484
  • 112
  • 300
  • 368
  • 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

42

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,291
  • 1
  • 16
  • 21
10
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,230
  • 1
  • 20
  • 42