How to specify the sort order for the query to a content provider
16,527
Solution 1
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");
Solution 2
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")
;
Related videos on Youtube
Author by
SHRISH M
Updated on December 30, 2020Comments
-
SHRISH M over 3 years
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);
-
Phantômaxx over 9 years
-
Cor about 2 yearsadditional 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.
-
-
Kirill Karmazin almost 7 yearsfor example if you're looking for images and you want to see the latest first - add: "date_modified DESC"