It's possible to use expandable list items with new RecyclerView? Like ExpandableListView?
Expandable RecyclerView is one of the most important feature in Android which can be easily created for our application . It contains two views one is parent view and other is child view. Parent is visible by default but the child view has to be expanded and collapsed. It will expand when we click on parent view.
Android ExpandableListView is a view that shows items in a vertically scrolling two-level list. It differs from a ListView by allowing two levels which are groups that can be easily expanded and collapsed by touching to view and their respective children items.
Android does not provide direct API for Expandable list using RecyclerView. The Android developer guide provides “ExpandableListView” that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children.
By default, clicking the entire parent view will trigger expansion or collapsing. However, Expandable RecyclerView allows for one or more sub views to handle expansion/collapsing and ignore touch event on the parent view itself.
A list RecyclerViews are items of a parent RecyclerView. The parent RecyclerView with vertical scrolling containing a list of RecyclerViews that are also with vertical scrolling and each of them can be expanded or collapsed. nested_recycler_item_child.xml
Custom Expand/Collapse Button By default, clicking the entire parent view will trigger expansion or collapsing. However, Expandable RecyclerView allows for one or more sub views to handle expansion/collapsing and ignore touch event on the parent view itself.
This is simple to do with the stock LayoutManagers, it all depends on how you manage your adapter.
When you want to expand a section you just add new items to your adapter after the header. Remember to call notifyItemRangeInserted when you do this. To collapse a section you simply remove the relevant items, and call notifyItemRangeRemoved(). For any data changes that are appropriately notified, the recycler view will animate the views. When adding items, an area to be filled with the new items is made, with the new items fading in. Removal is the opposite. All you need to do besides the adapter stuff is to style your views to convey the logical structure to the user.
Update: Ryan Brooks has now written an article on how to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With