/** * @param groupIndex representing the index of a group within {@link #groups} * @return the index of a group within the {@link #getVisibleItemCount()} */ public int getFlattenedGroupIndex(int groupIndex) { int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal; }
/** * @param listPosition representing either a child or a group * @return the index of a group within the {@link #getVisibleItemCount()} */ public int getFlattenedGroupIndex(ExpandableListPosition listPosition) { int groupIndex = listPosition.groupPos; int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal; }
/** * Converts the details of a child's position to a flat list position. * * @param groupIndex The index of a group within {@link #groups} * @param childIndex the index of a child within it's {@link ExpandableGroup} * @return The flat list position for the given child */ public int getFlattenedChildIndex(int groupIndex, int childIndex) { int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal + childIndex + 1; }
/** * Converts a child position to a flat list position. * * @param listPosition The child positions to be converted in it's * {@link ExpandableListPosition} representation. * @return The flat list position for the given child */ public int getFlattenedChildIndex(ExpandableListPosition listPosition) { int groupIndex = listPosition.groupPos; int childIndex = listPosition.childPos; int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal + childIndex + 1; }
/** * @return the total number visible rows */ public int getVisibleItemCount() { int count = 0; for (int i = 0; i < groups.size(); i++) { count += numberOfVisibleItemsInGroup(i); } return count; }
/** * @param group an {@link ExpandableGroup} within {@link #groups} * @return the index of a group within the {@link #getVisibleItemCount()} or 0 if the * groups.indexOf cannot find the group */ public int getFlattenedGroupIndex(ExpandableGroup group) { int groupIndex = groups.indexOf(group); int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal; }
/** * Translates a flat list position (the raw position of an item (child or group) in the list) to * either a) group pos if the specified flat list position corresponds to a group, or b) child * pos if it corresponds to a child. Performs a binary search on the expanded * groups list to find the flat list pos if it is an exp group, otherwise * finds where the flat list pos fits in between the exp groups. * * @param flPos the flat list position to be translated * @return the group position or child position of the specified flat list * position encompassed in a {@link ExpandableListPosition} object * that contains additional useful info for insertion, etc. */ public ExpandableListPosition getUnflattenedPosition(int flPos) { int groupItemCount; int adapted = flPos; for (int i = 0; i < groups.size(); i++) { groupItemCount = numberOfVisibleItemsInGroup(i); if (adapted == 0) { return ExpandableListPosition.obtain(ExpandableListPosition.GROUP, i, -1, flPos); } else if (adapted < groupItemCount) { return ExpandableListPosition.obtain(ExpandableListPosition.CHILD, i, adapted - 1, flPos); } adapted -= groupItemCount; } throw new RuntimeException("Unknown state"); }