GithubHelp home page GithubHelp logo

smailbarkouch / android-treeview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from newforma/androidtreeview

0.0 0.0 0.0 279 KB

TreeView implementation for android

License: Apache License 2.0

Kotlin 100.00%

android-treeview's Introduction

android-treeview

Recent changes

Entire library code converted to Kotlin for better stability and reducing null pointer errors though could be used with java as well

2D scrolling mode added, keep in mind this comes with few limitations: you won't be able not place views on right side like alignParentRight. Everything should be align left. Is not enabled by default

Use in your project

Click here for info on how to use this library in your android application.

Features

    1. N - level expandable/collapsable tree
    1. Custom values, views, styles for nodes
    1. Save state after rotation
    1. Selection mode for nodes
    1. Dynamic add/remove node

Known Limitations

  • For Android 4.0 (+/- nearest version) if you have too deep view hierarchy and with tree its easily possible, your app may crash

Integration

1) Add library as a dependency to your project

implementation 'com.github.SmailBarkouch:android-treeview:1.0.0'

2) Create your tree starting from root element. TreeNode.root() element will not be displayed so it doesn't require anything to be set.

val root = TreeNode.root()

Create and add your nodes (use your custom object as constructor param)

 val parent = TreeNode("MyParentNode")
 val child0 = TreeNode("ChildNode0")
 val child1 = TreeNode("ChildNode1")
 parent.addChildren(child0, child1)
 root.addChild(parent)

3) Add tree view to layout

 val tView = AndroidTreeView(getActivity(), root)
 containerView.addView(tView.getView())

The simplest but not styled tree is ready. Now you can see parent node as root of your tree

4) Custom view for nodes

Extend TreeNode.BaseNodeViewHolder and overwrite createNodeView method to prepare custom view for node:

class MyHolder : TreeNode.BaseNodeViewHolder<IconTreeItem> {
    ...
    override fun createNodeView(val node, val value) : View?{
        val inflater = LayoutInflater?.from(context)
        val view = inflater?.inflate(R.layout.layout_profile_node, container, false)
        val tvValue = view?.findViewById(R.id.node_value) as? TextView
        tvValue.setText(value.text)
        
        return view
    }
    ...
    class IconTreeItem {
        val icon
        val text
    }
}

5) Connect view holder with node

  val nodeItem = IconTreeItem()
  val child1 = TreeNode(nodeItem).setViewHolder(new MyHolder(mContext))

6) Consider using

TreeNode.setClickListener(TreeNodeClickListener listener)
AndroidTreeView.setDefaultViewHolder
AndroidTreeView.setDefaultNodeClickListener
...

android-treeview's People

Contributors

bmelnychuk avatar smailbarkouch avatar mathiasberwig avatar kshivang avatar allonmj avatar pbenware23 avatar szigetipeter avatar yehe01 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.