Android Tree View

This is a simple to use Tree implementation for Android. This page will show you some examples for using the tree.

Include into your layout

First of all, you will need to include the Tree into your layout xml file. In the simplest case this may look like this.
	<?xml version="1.0" encoding="utf-8"?>
	<LinearLayout xmlns:android=""


Use as it is

Here we will show you how to use without any subclassing. As you can see, you simply need to create a structure of TreeObjects, and assign this to the Tree View. The default Renderer will use the toString() method of the supplied Object to be displayed.
   ITreeObject root = new TreeObject("Root");
   ITreeObject child = new TreeObject("Child 1");
   child = new TreeObject("Child 2");
   ITreeObject subchild = new TreeObject("Child 2.1");
   Tree tree = (Tree) findViewById(;
The resulting Tree will look like this:

Handle user interaction

To get notififed if a user clicks on the tree, you may set an TreeListener by calling the Trees setTreeListener() method.

Use your own TreeObject class

If you have special needs, you may use your own TreeObject subclass or even implement the Interface ITreeObject completely by yourself. Here we will show you a simple subclass which changes the toString() method for customized rendering (This could also be done by subclassing the Tree as shown later).
   class MyTreeObject extends TreeObject<Person>
      public MyTreeObject(Person person)

      public String toString()
         return person.getName();

Use your own Tree subclass

To change the rendering completely you may create a subclass of tree as shown here. You will need to override the getView() method. This works like an ListViewAdapters getView() method.
    public View getView(View convertView, ITreeObject value)
	DefaultRendererView view = super.getView(convertView, value);
        Person person = (Person)value;
        return view;
The DefaultRendererView also shows the handles to open or close the Tree. If you want even more customization, you may avoid calling super.getView() and return your very own View.