Recyclerview in Android realizes multi-level folding list effect (II)

preface

Before starting this article, please take a look at this article: https://www.oudahe.com/p/25420/

The above article was written before. I found that there are many places that are not easy to use. I also learned some new postures and changed many places. Let's take a look at the detailed introduction:

main points:

1. You can control the display of items through the background

2. Treerecycleradapter, which can be expanded, folded and displayed at multiple levels

3. The adapter can be extended using decorator mode. It supports emptyadapter. Headview and footview can be added

4. The style of item can be documented, and the type corresponds to class to realize background control and reuse of the same item

Train of thought: (including the train of thought of the first article)

1. The adapter should only care about the contents of list < baseitem > data

2. Treat each item as an independent individual. The layout style, the proportion of each row, and onbindviewholder are implemented by each item.

3. Each item should only care about its own data and its own data at the next level, not its superiors and subordinates

4. Expand the implementation. When you click item, take out the sub data, and then add it to the data of the adapter to become the same level, because only your own subordinate data will be expanded.

5. Implement folding, get the subordinate data (understandably because of the files in a folder), and then delete these data from the data of the adapter.

6. Background control can save the class of item to the collection by initializing the registration method

7. The background returns the field, obtains the corresponding class file, and constructs the instance through the class. Newinstance() method

8. Write the viewholder and adapter in common. You do not need to write multiple adapters and viewholders, but only multiple baseitem. And baseitamdata (JavaBean)

Directory introduction

Here's an ugly picture:

Some codes are posted below:

(1) . baserecycleradapter:

(2) . treerecycleradapter

(3) . baseitem (some get.set codes are omitted)

(4) . treeitem

(5) . treeitemgroup

(6) . treeselectitemgroup

Specific application examples and effects:

1. Shopping page:

Code in Demo:

2. Multi level list

Code in Demo:

3. List of multiple types

Summary:

1. I think pages like shopping carts are very complex. Since multi-level lists are written, why not expand one

2. I saw a lot of packages in the click event of recyclerview, and found that many of them were reset every time the onbindviewholder was set, which was very bad

3. I like to let adatper hold the data set, and then add, delete, modify and query through the adapter. I'm not used to holding the data set directly in the activity (- -)

4. The habit of using without bugs is a good thing. If you think it's practical or you can learn posture, just praise it, ha ha

5. Most of the logic is in the item. Because it is split, you will find that there are not many codes for each item

6. I have used the multi-level list in a project (- -), but I haven't found any problems (simple use of multi-level list --)

The detailed code of demo. Is attached below

GitHub portal: treerecyclerview

Local download: http://xiazai.jb51.net/201705/yuanma/TreeRecyclerView (jb51.net).rar

Well, the above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message. Thank you for your support for 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
分享
二维码
< <上一篇
下一篇>>