我有一个包含三列的 sqlite 数据库:id、日期和字符串。对于一个日期,可以有多个与之关联的字符串,因此我有多个具有相同日期的行,只是字符串不同。
我想使用 ExpandableListView 来显示此数据。我需要在 SimpleCursorTreeAdapter 中实现 getChildrenCursor() 才能将其用于此目的,但我不确定该怎么做。我看过this我看到它使用 managedQuery,但我没有内容提供者,所以我不能使用它。来 self understand , getChildrenCursor() 的目的是获取一个游标,其中只包含可以放入子项中的数据,但我看不出这种方法如何根据日期分隔条目,因为它只将游标作为参数。
最佳答案
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);
}
}
关于android - 帮助 SimpleCursorTreeAdapter 和 getChildrenCursor(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5202161/