Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expandable list with RecyclerView?

It's possible to use expandable list items with new RecyclerView? Like ExpandableListView?

like image 499
Dariusz Rusin Avatar asked Oct 17 '14 06:10

Dariusz Rusin


People also ask

What is expandable RecyclerView?

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.

How do you use expandable list 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.

Is it possible to expand a list in Android using recyclerview?

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.

What is the use of expandable recyclerview?

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.

What are a list recyclerviews?

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

How do I expand a view in recyclerview?

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.


1 Answers

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.

like image 87
Tonic Artos Avatar answered Oct 19 '22 04:10

Tonic Artos