Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

italankin/android-expandable-list

Repository files navigation

Expandable List

Screenshot

Implementation of expandable list in Android.

ExpandableList

ExpandableList data structure supports:

  • lists with any depth
  • animations via RecyclerView.Adapter.notifyItemRange***
  • can also be used with ListView

Expanding/collapsing:

int nodeIndex = expandableList.indexOf(node);
if (node.isExpanded()) {
    int collapsed = expandableList.collapse(node);
    if (collapsed > 0) {
        adapter.notifyItemRangeRemoved(nodeIndex + 1, collapsed);
    }
} else {
    int expanded = expandableList.expand(node);
    if (expanded > 0) {
        adapter.notifyItemRangeInserted(nodeIndex + 1, expanded);
    }
}
adapter.notifyItemChanged(nodeIndex);