You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Android RecyclerView Adapter with nested items & expand/contract functionality
With AccordionRecycler you can easily create awesome RecyclerViews, containing infinitely nested items and the ability to expand or collapse any part of the View at will.
Have your Model Classes implement theAccordionRecyclerData interface.
The Adapter needs a way to get the ViewType, Primary data and the Enclosed (child) data, if existing. You use the above interface to provide those.
Fill the diamond operator with the type the model provides.
Optionally, you can use a base class as a reference for your different data sub-classes and also your ViewHolders. In the provided demo, and examples below, ColorData is the base class and it provided itself.
Create an Adapter that extends theAccordionRecyclerAdapter abstract class.
Override thebuildViewHolder function to provide new ViewHolder instances.
Override theupdateViewHolder function to update each item being recycled. TheAccordionRecyclerItemDetails parameter contains information about the current item and all enclosing (parent) items, when existing. This allows for unlimited visual combinations for all view types.
Expand/Collapse is accomplished with:
removeItem to remove an item and all it's child items, if existing.
removeEnclosedItems to remove the child items only.
addItems to add all items and their child items, if existing.
addEnclosedItems to add all items as child items to another.
Optionally, you can modify how each item is handled when it is iterated and added into the recycler data. You do that by overriding theprocessForAdditionalItems function. You can use this feature to handle edge case. One such case is shown in the demo, in which whenever a Pink item does not have any child White items, a new item is added, showing the text 'Nothing to see here'.
Copyright 2018 Fanis VeizisLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
About
Android RecyclerView Adapter with nested items & expand/contract functionality