Android 在 ORMLite 中使用 OrderBy

Android use OrderBy in ORMLite

我正在尝试为此代码使用链接 orderBy

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).query();

我找不到关于如何在使用 .query() 之前为此代码使用 orderBy() 链的好文档,例如此代码:

GenericRawResults<String[]> raw_result =G.messagesListsDao.queryRaw("SELECT * FROM messageslist WHERE group_id = " + group_id + " ORDER BY received_date");

至:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).orderby("id",false).query();

您可以多次调用 orderBy(),如下所示:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).orderBy("id",false).orderBy("received_date",false).query();

这包含在文档中。引用:

Add "ORDER BY" clause to the SQL query statement to order the results by the specified column name. Use the ascending boolean to get a ascending or descending order. This can be called multiple times to group by multiple columns.

希望有用!