Skip to content
TreeView implement in Android with RecyclerView.
Branch: master
Clone or download
Latest commit c95d511 Jan 15, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea fix the bug about adapter.ifCollapseChildWhileCollapseParent(true) Jan 19, 2017
app bug fix Jan 7, 2018
gradle/wrapper build.gradle fix Jan 7, 2018
raw add gif Oct 1, 2016
recyclertreeview-lib change padding to start/end Jan 12, 2019
.gitignore Initial commit Oct 1, 2016
LICENSE.txt Initial commit Oct 1, 2016 update demo and README Jan 19, 2017
build.gradle Update build.gradle Jan 7, 2018 Initial commit Oct 1, 2016
gradlew Initial commit Oct 1, 2016
gradlew.bat Initial commit Oct 1, 2016
settings.gradle Initial commit Oct 1, 2016


TreeView implement in Android with RecyclerView..




root build.gradle

allprojects {
    repositories {
        maven { url "" }

app build.gradle

dependencies {
    compile 'com.github.TellH:RecyclerTreeView:1.2.0'

Quick Start

  • Create a Java bean class and implement the LayoutItemType, to attach item layout id to it.
public class Dir implements LayoutItemType {
    public String dirName;

    public Dir(String dirName) {
        this.dirName = dirName;

    public int getLayoutId() {
        return R.layout.item_dir;
  • Create a ViewBinder to bind view with the data bean. As you see, provideViewHolder(View itemView) corresponds for onCreateViewHolder in RecyclerView, and bindView corresponds for onBindViewHolder in RecyclerView.
public class FileNodeBinder extends TreeViewBinder<FileNodeBinder.ViewHolder> {
    public ViewHolder provideViewHolder(View itemView) {
        return new ViewHolder(itemView);

    public void bindView(ViewHolder holder, int position, TreeNode node) {
        File fileNode = (File) node.getContent();

    public int getLayoutId() {
        return R.layout.item_file;

    public class ViewHolder extends TreeViewBinder.ViewHolder {
        public TextView tvName;

        public ViewHolder(View rootView) {
            this.tvName = (TextView) rootView.findViewById(;

  • Add TreeNode to TreeViewAdapter.
        List<TreeNode> nodes = new ArrayList<>();
        TreeNode<Dir> app = new TreeNode<>(new Dir("app"));
                new TreeNode<>(new Dir("manifests"))
                        .addChild(new TreeNode<>(new File("AndroidManifest.xml")))
                new TreeNode<>(new Dir("java")).addChild(
                        new TreeNode<>(new Dir("tellh")).addChild(
                                new TreeNode<>(new Dir("com")).addChild(
                                        new TreeNode<>(new Dir("recyclertreeview"))
                                                .addChild(new TreeNode<>(new File("Dir")))
                                                .addChild(new TreeNode<>(new File("DirectoryNodeBinder")))
                                                .addChild(new TreeNode<>(new File("File")))
                                                .addChild(new TreeNode<>(new File("FileNodeBinder")))
                                                .addChild(new TreeNode<>(new File("TreeViewBinder")))
        TreeNode<Dir> res = new TreeNode<>(new Dir("res"));
                new TreeNode<>(new Dir("layout"))
                        .addChild(new TreeNode<>(new File("activity_main.xml")))
                        .addChild(new TreeNode<>(new File("item_dir.xml")))
                        .addChild(new TreeNode<>(new File("item_file.xml")))
                new TreeNode<>(new Dir("mipmap"))
                        .addChild(new TreeNode<>(new File("ic_launcher.png")))
        TreeViewAdapter adapter = new TreeViewAdapter(nodes, Arrays.asList(new FileNodeBinder(), new DirectoryNodeBinder()));
  • set TreeNodeListener to TreeViewAdapter
        adapter.setOnTreeNodeListener(new TreeViewAdapter.OnTreeNodeListener() {
            public boolean onClick(TreeNode node, RecyclerView.ViewHolder holder) {
                if (!node.isLeaf()) {
                    //Update and toggle the node.
                    onToggle(!node.isExpand(), holder);
                return false;

            public void onToggle(boolean isExpand, RecyclerView.ViewHolder holder) {
                DirectoryNodeBinder.ViewHolder dirViewHolder = (DirectoryNodeBinder.ViewHolder) holder;
                final ImageView ivArrow = dirViewHolder.getIvArrow();
                int rotateDegree = isExpand ? 90 : -90;

Please check out the Demo and source code for more information. If you have any question, feel free to raise an issue. Thanks a lot!

You can’t perform that action at this time.