
tree-view-list-android
This project has moved to Github.
Introduction
This is a small widget that provides quite configurable tree view list. It is based on standard android list view.
Note that using generic tree is probably not the best approach for Android (or any other mobile) UI. see http://developer.android.com/design/index.html for all the control that it makes sense to use. Thus tree view should be considered as deprecated.
The widget is fully configurable - with your custom adapter you can provide your own implementation of the item views - even completely different implementation of item views depending on the tree level you are at. Implementation follows best approach of Adapters from android so views at the same tree level are reusable.
Examples
Example of trees :
| |
|
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Usage
The whole project can be included as external android library. After unsetting the "isLibrary?" flag, the project can also be compiled and installed on its own - providing demo application that presents capability of the widget. It shows how the tree behaves dynamically including explanding and collapsing nodes for many/all node, providing context menu for the tree, custom tree view with checkboxes only available for leaf nodes, custom colouring and different text sizes for text for different levels of the tree (albeit ugly) of the tree. The activity handling it is TreeViewListDemo.java, adapters used are SimpleStandardAdapter.java and extending it, colorful FancyColouredVariousSizesAdapter.java. Layout for tree items is defined in demo_list_item.xml. You can learn from the demo how to use the widget. The tree can be configured through XML layout file (attributes are defined in attrs.xml ). Example usage for demo application is in main.xml. It is most convenient to build your tree to display using TreeBuilder.java
Architecture
The architecture separates out different aspects of the tree: there is a separate list view, tree adapter, tree state manager and tree state builder.
- Tree view provides the frame to display the view TreeViewList.java. This class should be used in XML layout or manually added to your view hierarchy.
- Adapter allows to create visual representation of each tree node. The adapter should be overridden by a concrete implementation that will provide views created at each level of the treee. Base class for all tree adapters is AbstractTreeViewAdapter.java
- State manager provides storage for tree state (connections between parents and children, collapsed/expanded state). It provides all the low-level tree manipulation methods. It is abstracted to only basic methds accessing tree state in the interface: TreeStateManager.java and implemented in InMemoryTreeStateManager.java. Several adapters can share the sate state manager, and all the state will be shared (so not only parent/child relationship but also collapsed/expanded nodes) - you can this way switch between different "visualisations' of the same tree.
- Tree builder allows to build tree easily providing higher level methods. The tree can be build either from prepared sequentially prepared list of nodes (node id, level) or using (parent/child relationships). TreeBuilder.java
For now only in-memory state manager InMemoryTreeStateManager is provided, but Tree State Manger interface is done in the way that database tree manager even for large trees is potentially supported.