我有一个包含三列的sqlite数据库: id、日期和字符串。对于单个日期,可以有多个字符串与之关联,因此我有多个日期相同但字符串不同的行。
我想使用ExpandableListView来显示这些数据。我需要在SimpleCursorTreeAdapter中实现getChildrenCursor()以便将其用于此目的,但我不确定如何做到这一点。我看过this,我看到它使用managedQuery,但我没有内容提供商,所以我无法使用它。根据我的understand,getChildrenCursor()的目的是获得一个只包含可以放入子对象中的数据的游标,但是我不明白这个方法如何根据条目的日期来分隔条目,因为它只作为参数传递了一个游标。
发布于 2011-03-07 15:11:46
public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {
public MyExpandableListAdapter(Cursor cursor, Context context, int groupLayout,
int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
int[] childrenTo) {
super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childrenFrom,
childrenTo);
}
@Override
@SuppressWarnings("deprecation")
protected Cursor getChildrenCursor(Cursor groupCursor) {
// Given the group, we return a cursor for all the children within that group
// Return a cursor that points to this contact's phone numbers
Uri.Builder builder = People.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, groupCursor.getLong(mGroupIdColumnIndex));
builder.appendEncodedPath(People.Phones.CONTENT_DIRECTORY);
Uri phoneNumbersUri = builder.build();
// The returned Cursor MUST be managed by us, so we use Activity's helper
// functionality to manage it for us.
return managedQuery(phoneNumbersUri, mPhoneNumberProjection, null, null, null);
}
}发布于 2011-11-24 05:57:29
我知道已经晚了8个月了,但还是。
您可以在没有内容提供商的情况下创建光标。打开SQLite数据库并执行db.query(...) -这将为您创建一个游标。这与内容提供商创建光标的方式相同。
发布于 2014-07-09 06:58:34
不应使用managedQuery,因为它已在API11中折旧。
groupCursor对象可以用来表示get一个"_id“,用于查询它的子数据。"?“是来自组游标的ID列,它最有可能用作另一个表上的外键。
https://stackoverflow.com/questions/5202161
复制相似问题