A
A
Artem2013-07-01 00:19:14
Android
Artem, 2013-07-01 00:19:14

Multilevel ExpandableListView?

It is necessary to implement a multi-level ExpandableListView in the application. Without checkboxes and other things, a simple drop-down list with the processing of a click on the final item. There will not be many levels (2-3, maximum 4), but the data is loaded into it from the server and the amount can change accordingly over time, and the application must be ready for this.
Is there any out-of-the-box solution for this task? Maybe someone came across, some kind of library or implementation example? In principle, it would be interesting even outwardly to see how other people see it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
erakitin, 2013-07-01
@erakitin

Faced with a similar task, it was necessary to display a tree of devices with hiding / revealing child nodes. For a long time I was looking for a ready-made solution, but I could not find anything suitable. I solved the problem very simply using ListView, though I also had to write a wrapper class with methods for working with a tree and extend the node class with additional fields (nesting level; a flag indicating whether the node is hidden / disclosed).
Now let's move on to the algorithm.
1. Recursively traversing the tree, we collect an ArrayList from the expanded nodes, not forgetting to specify the nesting level for the nodes, then we feed this ArrayList to the adapter.
2. In the getView method of the adapter, we set the indent to the left of the view content, proportional to the nesting level (or use a different layout for nested nodes, or somehow select nested nodes).
3. By clicking on the icon for hiding/expanding a node, set the appropriate flag for this node. Then, we do everything the same as in paragraph 1, but do not forget to call the notifyDataSetChanged () method of our adapter.
I hope this information will be useful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question