【问题标题】:How to specify the sort order for the query to a content provider如何为内容提供者的查询指定排序顺序
【发布时间】:2014-12-29 09:42:21
【问题描述】:

我正在尝试从 Android 中的 Sqlite 表中加载所有项目并希望对结果进行排序。

如何指定返回游标的顺序?

我通过 CursorLoader 通过以下方式查询 ContentProvider:

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

【问题讨论】:

标签: android android-sqlite android-contentprovider android-cursorloader


【解决方案1】:

尝试下面的代码更改 COLUMN_NAME 为您想要排序的实际列名。

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

【讨论】:

  • 例如,如果您正在查找图像并且希望首先查看最新的 - 添加:“date_modified DESC”
【解决方案2】:
new CursorLoader(context, RepresentativeEntityContentProvider.CONTENT_URI, null, null,
            null, "column_name ASC");

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

;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多