Android Treeview

前端 未结 10 1847
野的像风
野的像风 2020-12-02 09:30

I know there is the ExpandableListView but it only supports up to 2 levels. I need a true treeview vertical list with at least up to ~5 levels (more is better).

Any

相关标签:
10条回答
  • 2020-12-02 09:38

    Answering my own question, since we implemented this many months ago.

    Our implementation in an open-source proejct.

    0 讨论(0)
  • 2020-12-02 09:41

    I think if multilevel expandablelist is done properly it actually works and looks great. Here is another example of http://code.google.com/p/tree-view-list-android/

    enter image description here

    0 讨论(0)
  • 2020-12-02 09:41

    I agree with pjv, at least for phone-size devices. It would be better to organize the widget to show one group of siblings at a time in a ListView. This could be done in a single activity that keeps track of its position in the tree. It could show a header with breadcrumbs showing the path to the parent of the items currently on display.

    A multi-level tree view may be appropriate for a tablet device, but a phone does not have enough real estate to support the proposed 5 levels (with everything having to be big enough for fingers).

    Nevertheless, if you are set on a tree view, don't look at subclassing ExpandableListView. It operates internally by packing the parent and child indices (each an int) into a single long. This internal representation makes it virtually impossible to extend beyond 2 levels.

    0 讨论(0)
  • 2020-12-02 09:43

    i solved it for me, posting in a similar thread: other thread

    enter image description here

    0 讨论(0)
  • 2020-12-02 09:44

    I have found an easier solution to this problem, as I myself am somewhat intermediate in my coding skills. In my situation, I needed a Windows-themed Tree View, which after brainstorming ideas, I was able to implement with hardly any coding!

    Here's the trick: use a WebView and an embedded HTML page to display a custom Tree View, and use Android's super handy JavaScript communication interface to receive selections & clicks: Proof of Concept Example on Android-er Blog

    With this power we can take advantage of a large collection of JS/CSS control snippets around the web. Themeable Windows7-Style jQuery TreeView control -- jsTree

    Lot's of possibilities and power with Android out there, happy coding!

    0 讨论(0)
  • 2020-12-02 09:47

    I'd start by making the data structure more representative of what it's meant to contain. Since you have an array of items and each child can have it's own array of items, each with its own array, etc. I'd consider using a class with two members: an object that represents the data for this particular item and an array that holds the item's children. Each child would itself be an instance of the class so that it, too, could have children.

    private class ParentAndKids { Object parent; Array kids; }

    Your adapter would then have an array of ParentAndKids objects which represents the top layer. You'd add and remove list items based on which parents were expanded.

    0 讨论(0)
提交回复
热议问题