How to use Android expandablerecyclerview

This article shares the use of Android expandablerecyclerview for your reference. The specific contents are as follows

1. At present, only two-level structure is supported. 2. All groups can be expanded at the same time, and only one group can be expanded at the same time. 3. Groupview and childview are highly customized. 4. When initialization data is supported, specify to expand a group of data. 5. Onlick and onlongclick events of groupitem and childitem are supported. 6. Expand and retract the tape animation.

design sketch:

Usage steps: add dependency

1. Inherit baseviewholder and implement your own viewholder

1.1 initialize your view (including groupview and childview) in the constructor

1.2 implement the following two methods respectively, and return the ID of the root node in the corresponding layout file in the corresponding method.

Example code:

Example adapter code:

After completing the above two steps, we are basically finished. Because the data of expandablerecyclerview is to be grouped, recyclerviewdata is provided to encapsulate it

Next, let's look at how the data is encapsulated.

All the work is completed. Now you can write code happily as usual using adapter and recyclerview.

Note: when adding or deleting metadata mdats, you need to call adapter. Notifyrecyclerviewdata(); Otherwise, the data index will be disordered.

Code GitHub address

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>