- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
public static Cursor getListGroupCursor(Activity activity,
ShopListItem list, boolean marked) {
long state = marked ? Cells.PURCHAZED_STATE : Cells.WANT_TO_BUY_STATE;
String where;
String[] arg;
if (list.isAutoList()) {
where = Cells.STATE + " = ?";
arg = new String[] { Long.toString(state) };
} else {
where = Cells.LIST_ID + " = ? AND " + Cells.STATE + " = ?";
arg = new String[] { Long.toString(list.getId()),
Long.toString(state) };
}
Cursor c = activity.managedQuery(Cells.CONTENT_URI,
new String[] { Cells.CATEGORY_ID }, where, arg,
Cells.DISTINCT_SORT_ORDER);
ArrayList<Long> ids = new ArrayList<Long>();
while (c != null && c.moveToNext()) {
ids.add(new Long(c.getLong(c.getColumnIndex(Cells.CATEGORY_ID))));
}
if (c != null) {
c.close();
}
int count = ids.size();
String whereGroup = null;
String[] argGroup = null;
if (count > 0) {
whereGroup = "";
argGroup = new String[count];
for (int i = 0; i < count; i++) {
if (i < count - 1) {
whereGroup += (Categories._ID + "= ? OR ");
} else {
whereGroup += (Categories._ID + "= ?");
}
argGroup[i] = Long.toString(ids.get(i));
// Log.i(tag, "getListGroupCursor "+argGroup[i]);
}
} else {
whereGroup = Categories._ID + "= -1";
}
Cursor groupCursor = activity.managedQuery(Categories.CONTENT_URI,
null, whereGroup, argGroup, Categories.DEFAULT_SORT_ORDER);
return groupCursor;
}
Работа с ContentProvider в android. Выборка категорий, id которых присутствуют в результатах первой выборки (по признаку)