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")

;

Share:
16,527

Related videos on Youtube

SHRISH M
Author by

SHRISH M

Updated on December 30, 2020

Comments

  • SHRISH M
    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
      Phantômaxx over 9 years
    • Cor
      Cor about 2 years
      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.
  • Kirill Karmazin
    Kirill Karmazin almost 7 years
    for example if you're looking for images and you want to see the latest first - add: "date_modified DESC"