GROUP BY与CursorLoader [英] GROUP BY with CursorLoader
问题描述
如何定义一个 GROUP BY
查询我CursorLoader?
How do I define a GROUP BY
query for my CursorLoader?
这两个构造为 CursorLoader
我看拿一个单上下文
或背景
,乌里
,预测
,选择
, selectionArgs两个
和排序顺序
。
The two constructors for a CursorLoader
I see take either a single Context
or a Context
, Uri
, projection
, selection
, selectionArgs
and sortOrder
.
但是,没有 GROUPBY
。
(我用的是Android 2.3设备的支持包)
(I'm using the support package for a Android 2.3 device)
推荐答案
不是真的...
您可以定义一个特定的URI您的具体GROUP BY子句。
You can define a specific URI to your specific GROUP BY clause.
例如,如果你有一个表mPersonTable,可能是按性别分组,您可以定义以下的URI:
For example, if you have a table mPersonTable, possibly grouped by gender, you can define the following URIs:
PERSON
PERSON/#
PERSON/GENDER
您查询的查询时,切换使您可以通过参数添加组:
When querying, switch between your queries so you can add your group by parameter:
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
String groupBy = null;
switch (mUriMatcher.match(uri)) {
case PERSON_ID:
...
break;
case PERSON_GENDER:
groupBy = GENDER_COLUMN;
case PERSON:
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(mPersonTable);
builder.setProjectionMap(mProjectionMap);
return builder.query(db, projection, selection, selectionArgs, groupBy, having, sortOrder, limit);
default:
break;
}
}
在事实上,你可以任何类型的参数传递到您的查询
In fact, you could pass any sort of parameters to your query
观测:使用UriMatcher到URI与您的查询实现匹配。
Obs.: Use a UriMatcher to match the uri with your query implementation.
这篇关于GROUP BY与CursorLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!