SimpleCursorTreeAdapterpublic abstract class SimpleCursorTreeAdapter extends ResourceCursorTreeAdapter An easy adapter to map columns from a cursor to TextViews or ImageViews
defined in an XML file. You can specify which columns you want, which views
you want to display the columns, and the XML file that defines the appearance
of these views. Separate XML files for child and groups are possible.
TextViews bind the values to their text property (see
{@link TextView#setText(CharSequence)}). ImageViews bind the values to their
image's Uri property (see {@link ImageView#setImageURI(android.net.Uri)}). |
Fields Summary |
---|
private int[] | mGroupFromThe indices of columns that contain data to display for a group. | private int[] | mGroupToThe View IDs that will display a group's data fetched from the
corresponding column. | private int[] | mChildFromThe indices of columns that contain data to display for a child. | private int[] | mChildToThe View IDs that will display a child's data fetched from the
corresponding column. |
Constructors Summary |
---|
public SimpleCursorTreeAdapter(android.content.Context context, android.database.Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, int lastChildLayout, String[] childFrom, int[] childTo)Constructor.
super(context, cursor, collapsedGroupLayout, expandedGroupLayout, childLayout,
lastChildLayout);
init(groupFrom, groupTo, childFrom, childTo);
| public SimpleCursorTreeAdapter(android.content.Context context, android.database.Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)Constructor.
super(context, cursor, collapsedGroupLayout, expandedGroupLayout, childLayout);
init(groupFrom, groupTo, childFrom, childTo);
| public SimpleCursorTreeAdapter(android.content.Context context, android.database.Cursor cursor, int groupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)Constructor.
super(context, cursor, groupLayout, childLayout);
init(groupFrom, groupTo, childFrom, childTo);
|
Methods Summary |
---|
protected void | bindChildView(android.view.View view, android.content.Context context, android.database.Cursor cursor, boolean isLastChild)
bindView(view, context, cursor, mChildFrom, mChildTo);
| protected void | bindGroupView(android.view.View view, android.content.Context context, android.database.Cursor cursor, boolean isExpanded)
bindView(view, context, cursor, mGroupFrom, mGroupTo);
| private void | bindView(android.view.View view, android.content.Context context, android.database.Cursor cursor, int[] from, int[] to)
for (int i = 0; i < to.length; i++) {
View v = view.findViewById(to[i]);
if (v != null) {
String text = cursor.getString(from[i]);
if (text == null) {
text = "";
}
if (v instanceof TextView) {
((TextView) v).setText(text);
} else if (v instanceof ImageView) {
setViewImage((ImageView) v, text);
} else {
throw new IllegalStateException("SimpleCursorAdapter can bind values only to" +
" TextView and ImageView!");
}
}
}
| private void | init(java.lang.String[] groupFromNames, int[] groupTo, java.lang.String[] childFromNames, int[] childTo)
mGroupTo = groupTo;
mChildTo = childTo;
// Get the group cursor column indices, the child cursor column indices will come
// when needed
initGroupFromColumns(groupFromNames);
// Get a temporary child cursor to init the column indices
if (getGroupCount() > 0) {
MyCursorHelper tmpCursorHelper = getChildrenCursorHelper(0, true);
if (tmpCursorHelper != null) {
initChildrenFromColumns(childFromNames, tmpCursorHelper.getCursor());
deactivateChildrenCursorHelper(0);
}
}
| private void | initChildrenFromColumns(java.lang.String[] childFromNames, android.database.Cursor childCursor)
mChildFrom = new int[childFromNames.length];
initFromColumns(childCursor, childFromNames, mChildFrom);
| private void | initFromColumns(android.database.Cursor cursor, java.lang.String[] fromColumnNames, int[] fromColumns)
for (int i = fromColumnNames.length - 1; i >= 0; i--) {
fromColumns[i] = cursor.getColumnIndexOrThrow(fromColumnNames[i]);
}
| private void | initGroupFromColumns(java.lang.String[] groupFromNames)
mGroupFrom = new int[groupFromNames.length];
initFromColumns(mGroupCursorHelper.getCursor(), groupFromNames, mGroupFrom);
| protected void | setViewImage(ImageView v, java.lang.String value)Called by bindView() to set the image for an ImageView. By default, the
value will be treated as a Uri. Intended to be overridden by Adapters
that need to filter strings retrieved from the database.
try {
v.setImageResource(Integer.parseInt(value));
} catch (NumberFormatException nfe) {
v.setImageURI(Uri.parse(value));
}
|
|