public abstract class CursorTreeAdapter extends BaseExpandableListAdapter implements Filterable
Cursor
s to an
ExpandableListView
widget. The top-level Cursor
(that is
given in the constructor) exposes the groups, while subsequent Cursor
s
returned from getChildrenCursor(Cursor)
expose children within a
particular group. The Cursors must include a column named "_id" or this class
will not work.Constructor and Description |
---|
CursorTreeAdapter(Cursor cursor,
Context context)
Constructor.
|
CursorTreeAdapter(Cursor cursor,
Context context,
boolean autoRequery)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
bindChildView(View view,
Context context,
Cursor cursor,
boolean isLastChild)
Bind an existing view to the child data pointed to by cursor
|
protected abstract void |
bindGroupView(View view,
Context context,
Cursor cursor,
boolean isExpanded)
Bind an existing view to the group data pointed to by cursor.
|
void |
changeCursor(Cursor cursor) |
String |
convertToString(Cursor cursor) |
Cursor |
getChild(int groupPosition,
int childPosition)
Gets the data associated with the given child within the given group.
|
long |
getChildId(int groupPosition,
int childPosition)
Gets the ID for the given child within the given group.
|
int |
getChildrenCount(int groupPosition)
Gets the number of children in a specified group.
|
protected abstract Cursor |
getChildrenCursor(Cursor groupCursor)
Gets the Cursor for the children at the given group.
|
View |
getChildView(int groupPosition,
int childPosition,
boolean isLastChild,
View convertView,
ViewGroup parent)
Gets a View that displays the data for the given child within the given
group.
|
Cursor |
getCursor() |
Filter |
getFilter()
Returns a filter that can be used to constrain data with a filtering
pattern.
|
FilterQueryProvider |
getFilterQueryProvider() |
Cursor |
getGroup(int groupPosition)
Gets the data associated with the given group.
|
int |
getGroupCount()
Gets the number of groups.
|
long |
getGroupId(int groupPosition)
Gets the ID for the group at the given position.
|
View |
getGroupView(int groupPosition,
boolean isExpanded,
View convertView,
ViewGroup parent)
Gets a View that displays the given group.
|
boolean |
hasStableIds()
Indicates whether the child and group IDs are stable across changes to the
underlying data.
|
boolean |
isChildSelectable(int groupPosition,
int childPosition)
Whether the child at the specified position is selectable.
|
protected abstract View |
newChildView(Context context,
Cursor cursor,
boolean isLastChild,
ViewGroup parent)
Makes a new child view to hold the data pointed to by cursor.
|
protected abstract View |
newGroupView(Context context,
Cursor cursor,
boolean isExpanded,
ViewGroup parent)
Makes a new group view to hold the group data pointed to by cursor.
|
void |
notifyDataSetChanged() |
void |
notifyDataSetChanged(boolean releaseCursors)
Notifies a data set change, but with the option of not releasing any
cached cursors.
|
void |
notifyDataSetInvalidated() |
void |
onGroupCollapsed(int groupPosition)
Called when a group is collapsed.
|
Cursor |
runQueryOnBackgroundThread(CharSequence constraint) |
void |
setChildrenCursor(int groupPosition,
Cursor childrenCursor)
Sets the children Cursor for a particular group.
|
void |
setFilterQueryProvider(FilterQueryProvider filterQueryProvider) |
void |
setGroupCursor(Cursor cursor)
Sets the group Cursor.
|
areAllItemsEnabled, getChildType, getChildTypeCount, getCombinedChildId, getCombinedGroupId, getGroupType, getGroupTypeCount, isEmpty, onGroupExpanded, registerDataSetObserver, unregisterDataSetObserver
public CursorTreeAdapter(Cursor cursor, Context context)
Cursor.requery()
on the cursor whenever
it changes so that the most recent data is always displayed.cursor
- The cursor from which to get the data for the groups.public CursorTreeAdapter(Cursor cursor, Context context, boolean autoRequery)
cursor
- The cursor from which to get the data for the groups.context
- The contextautoRequery
- If true the adapter will call Cursor.requery()
on the cursor whenever it changes so the most recent data is
always displayed.protected abstract Cursor getChildrenCursor(Cursor groupCursor)
If you want to asynchronously query a provider to prevent blocking the
UI, it is possible to return null and at a later time call
setChildrenCursor(int, Cursor)
.
It is your responsibility to manage this Cursor through the Activity
lifecycle. It is a good idea to use Activity.managedQuery(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String)
which
will handle this for you. In some situations, the adapter will deactivate
the Cursor on its own, but this will not always be the case, so please
ensure the Cursor is properly managed.
groupCursor
- The cursor pointing to the group whose children cursor
should be returnedpublic void setGroupCursor(Cursor cursor)
cursor
- The Cursor to set for the group. If there is an existing cursor
it will be closed.public void setChildrenCursor(int groupPosition, Cursor childrenCursor)
This is useful when asynchronously querying to prevent blocking the UI.
groupPosition
- The group whose children are being set via this Cursor.childrenCursor
- The Cursor that contains the children of the group.public Cursor getChild(int groupPosition, int childPosition)
ExpandableListAdapter
getChild
in interface ExpandableListAdapter
groupPosition
- the position of the group that the child resides inchildPosition
- the position of the child with respect to other
children in the grouppublic long getChildId(int groupPosition, int childPosition)
ExpandableListAdapter
ExpandableListAdapter.getCombinedChildId(long, long)
) must be unique across ALL items
(groups and all children).getChildId
in interface ExpandableListAdapter
groupPosition
- the position of the group that contains the childchildPosition
- the position of the child within the group for which
the ID is wantedpublic int getChildrenCount(int groupPosition)
ExpandableListAdapter
getChildrenCount
in interface ExpandableListAdapter
groupPosition
- the position of the group for which the children
count should be returnedpublic Cursor getGroup(int groupPosition)
ExpandableListAdapter
getGroup
in interface ExpandableListAdapter
groupPosition
- the position of the grouppublic int getGroupCount()
ExpandableListAdapter
getGroupCount
in interface ExpandableListAdapter
public long getGroupId(int groupPosition)
ExpandableListAdapter
ExpandableListAdapter.getCombinedGroupId(long)
) must be unique across ALL items
(groups and all children).getGroupId
in interface ExpandableListAdapter
groupPosition
- the position of the group for which the ID is wantedpublic View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
ExpandableListAdapter
ExpandableListAdapter.getChildView(int, int, boolean, View, ViewGroup)
.getGroupView
in interface ExpandableListAdapter
groupPosition
- the position of the group for which the View is
returnedisExpanded
- whether the group is expanded or collapsedconvertView
- the old view to reuse, if possible. You should check
that this view is non-null and of an appropriate type before
using. If it is not possible to convert this view to display
the correct data, this method can create a new view. It is not
guaranteed that the convertView will have been previously
created by
ExpandableListAdapter.getGroupView(int, boolean, View, ViewGroup)
.parent
- the parent that this view will eventually be attached toprotected abstract View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent)
context
- Interface to application's global informationcursor
- The group cursor from which to get the data. The cursor is
already moved to the correct position.isExpanded
- Whether the group is expanded.parent
- The parent to which the new view is attached toprotected abstract void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded)
view
- Existing view, returned earlier by newGroupView.context
- Interface to application's global informationcursor
- The cursor from which to get the data. The cursor is
already moved to the correct position.isExpanded
- Whether the group is expanded.public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
ExpandableListAdapter
getChildView
in interface ExpandableListAdapter
groupPosition
- the position of the group that contains the childchildPosition
- the position of the child (for which the View is
returned) within the groupisLastChild
- Whether the child is the last child within the groupconvertView
- the old view to reuse, if possible. You should check
that this view is non-null and of an appropriate type before
using. If it is not possible to convert this view to display
the correct data, this method can create a new view. It is not
guaranteed that the convertView will have been previously
created by
ExpandableListAdapter.getChildView(int, int, boolean, View, ViewGroup)
.parent
- the parent that this view will eventually be attached toprotected abstract View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent)
context
- Interface to application's global informationcursor
- The cursor from which to get the data. The cursor is
already moved to the correct position.isLastChild
- Whether the child is the last child within its group.parent
- The parent to which the new view is attached toprotected abstract void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild)
view
- Existing view, returned earlier by newChildViewcontext
- Interface to application's global informationcursor
- The cursor from which to get the data. The cursor is
already moved to the correct position.isLastChild
- Whether the child is the last child within its group.public boolean isChildSelectable(int groupPosition, int childPosition)
ExpandableListAdapter
isChildSelectable
in interface ExpandableListAdapter
groupPosition
- the position of the group that contains the childchildPosition
- the position of the child within the grouppublic boolean hasStableIds()
ExpandableListAdapter
hasStableIds
in interface ExpandableListAdapter
Adapter.hasStableIds()
public void notifyDataSetChanged()
notifyDataSetChanged
in class BaseExpandableListAdapter
DataSetObservable.notifyChanged()
public void notifyDataSetChanged(boolean releaseCursors)
releaseCursors
- Whether to release and deactivate any cached
cursors.public void notifyDataSetInvalidated()
notifyDataSetInvalidated
in class BaseExpandableListAdapter
DataSetObservable.notifyInvalidated()
public void onGroupCollapsed(int groupPosition)
ExpandableListAdapter
onGroupCollapsed
in interface ExpandableListAdapter
onGroupCollapsed
in class BaseExpandableListAdapter
groupPosition
- The group being collapsed.public String convertToString(Cursor cursor)
CursorAdapter.convertToString(Cursor)
public Cursor runQueryOnBackgroundThread(CharSequence constraint)
public Filter getFilter()
Filterable
Returns a filter that can be used to constrain data with a filtering pattern.
This method is usually implemented by Adapter
classes.
getFilter
in interface Filterable
public FilterQueryProvider getFilterQueryProvider()
CursorAdapter.getFilterQueryProvider()
public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider)
public void changeCursor(Cursor cursor)
CursorAdapter.changeCursor(Cursor)
public Cursor getCursor()
CursorAdapter.getCursor()