Stan Malcolm Stan Malcolm - 1 year ago 112
Android Question

RecyclerView with expandable items

I need to make an expandable

, with only one opened item per click (all others must close).
I know there is possibility to do this with the help of
and then use next code:

elv.setOnGroupExpandListener(new OnGroupExpandListener() {

public void onGroupExpand(int groupPosition) {
if (lastExpandedPosition != -1
&& groupPosition != lastExpandedPosition) {
lastExpandedPosition = groupPosition;

but is there the way to make the same with using

Answer Source

Here is a nice tutorial for expending RecyclerView from Big Nerd Ranch


  • Define two layouts: One for parent items and one for child items.
  • Define two ViewHolders for these layouts.
  • Define two classes for parent and child objects.
  • Parent object has to implement ParentObject interface.
  • Define custom adapter.
  • Call setParentAndIconExpandOnClick(true) on adapter.

For only one expanded view at a time, you can keep track of the last expanded view and close it when user cliced new one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download