/** * @param listPosition An {@link ExpandableListPosition} representing either a child or group * @return the total number of children within the group associated with the @param listPosition */ public int getExpandableGroupItemCount(ExpandableListPosition listPosition) { return groups.get(listPosition.groupPos).getItemCount(); }
@Override public ExpandableGroup createFromParcel(Parcel in) { return new ExpandableGroup(in); }
@Override public int getChildViewType(int position, ExpandableGroup group, int childIndex) { if (((Artist) (group).getItems().get(childIndex)).isFavorite()) { return FAVORITE_VIEW_TYPE; } else { return ARTIST_VIEW_TYPE; } } }
@Override public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); dest.writeBooleanArray(selectedChildren); }
public void setGenreTitle(ExpandableGroup genre) { if (genre instanceof Genre) { genreName.setText(genre.getTitle()); icon.setBackgroundResource(((Genre) genre).getIconResId()); } if (genre instanceof MultiCheckGenre) { genreName.setText(genre.getTitle()); icon.setBackgroundResource(((MultiCheckGenre) genre).getIconResId()); } if (genre instanceof SingleCheckGenre) { genreName.setText(genre.getTitle()); icon.setBackgroundResource(((SingleCheckGenre) genre).getIconResId()); } }
/** * @param group the index of the {@link ExpandableGroup} in the full collection {@link #groups} * @return the number of visible row items for the particular group. If the group is collapsed, * return 1 for the group header. If the group is expanded return total number of children in the * group + 1 for the group header */ private int numberOfVisibleItemsInGroup(int group) { if (expandedGroupIndexes[group]) { return groups.get(group).getItemCount() + 1; } else { return 1; } }
public static List<ExpandableGroup> makeGroups() { ArrayList list = new ArrayList(); for (int i = 0; i < 6; i++) { List items = Arrays.asList(i + ".0", i + ".1", i + ".2"); list.add(new ExpandableGroup("Section " + i, items)); } return list; }
@Override public void onBindChildViewHolder(ChildViewHolder holder, int flatPosition, ExpandableGroup group, int childIndex) { int viewType = getItemViewType(flatPosition); Artist artist = (Artist) group.getItems().get(childIndex); switch (viewType) { case ARTIST_VIEW_TYPE: ((ArtistViewHolder) holder).setArtistName(artist.getName()); break; case FAVORITE_VIEW_TYPE: ExpandableListPosition listPosition = expandableList.getUnflattenedPosition(flatPosition); ((SingleCheckArtistViewHolder) holder) .onBindViewHolder(flatPosition, childCheckController.isChildChecked(listPosition)); ((SingleCheckArtistViewHolder) holder).setArtistName(artist.getName()); } }
/** * Collapse a group * * @param listPosition position of the group to collapse */ private void collapseGroup(ExpandableListPosition listPosition) { expandableList.expandedGroupIndexes[listPosition.groupPos] = false; if (listener != null) { listener.onGroupCollapsed(expandableList.getFlattenedGroupIndex(listPosition) + 1, expandableList.groups.get(listPosition.groupPos).getItemCount()); } }
/** * Expand a group * * @param listPosition the group to be expanded */ private void expandGroup(ExpandableListPosition listPosition) { expandableList.expandedGroupIndexes[listPosition.groupPos] = true; if (listener != null) { listener.onGroupExpanded(expandableList.getFlattenedGroupIndex(listPosition) + 1, expandableList.groups.get(listPosition.groupPos).getItemCount()); } }
public void clearChoices() { childCheckController.clearCheckStates(); //only update the child views that are visible (i.e. their group is expanded) for (int i = 0; i < getGroups().size(); i++) { ExpandableGroup group = getGroups().get(i); if (isGroupExpanded(group)) { notifyItemRangeChanged(expandableList.getFlattenedFirstChildIndex(i), group.getItemCount()); } } }
/** * Clear any choices previously checked */ public void clearChoices() { childCheckController.clearCheckStates(); //only update the child views that are visible (i.e. their group is expanded) for (int i = 0; i < getGroups().size(); i++) { ExpandableGroup group = getGroups().get(i); if (isGroupExpanded(group)) { notifyItemRangeChanged(expandableList.getFlattenedFirstChildIndex(i), group.getItemCount()); } } }