Implementation of Android UI example of multi-level tree list TreeView

The so-called treeview is a common multi-level list tree in windows. In Android, the system only provides listview and expandablelistview by default, and only supports the implementation of secondary lists at most. Therefore, if we want to implement three-level and more levels of lists, we need to do some processing ourselves.

In fact, some people have tried to achieve this effect a long time ago, but there are some problems in the effect. My implementation idea mainly comes from the network, but on the basis of it, I corrected some logical errors and made some optimization.

Let's look at the effect first:

Then, let's talk about the general idea:

In fact, the multi-level list implemented here is only a visual effect. The grading effect we see is caused by the different indentation of each line. For example, in the above effect, Shandong Province and Guangdong Province are the highest levels. Qingdao under Shandong Province is a sub item of Shandong Province. We increase its left indent, so it seems to have a sense of hierarchy. The same goes for other levels.

In other words, we only use one listview. The focus of our work is to constantly change the data displayed by the listview, modify the data to the data content that the user wants to see according to the user's operation, and indent the display effect according to the different data items, so as to finally present the effect of a treeview.

For specific implementation ideas, refer to the following project structure and specific code:

Element.Java:

TreeViewAdapter.java:

TreeViewItemClickListener.java:

MainActivity.java:

treeview_ item.xml:

activity_ main.xml:

Download address: androidtreeviewdemo_ jb51.rar

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
分享
二维码
< <上一篇
下一篇>>