Git Product home page Git Product logo

treeview's Introduction

TreeView

An android tree view with high performance and rich functions

中文介绍

Captures

There are some gifs from Demo:

  • Select node:

  • Operate all:

Features

  • expandAll/collapseAll
  • expandNode/collapseNode
  • expandLevel/collapseLevel
  • toggleNode
  • deleteNode/addNode
  • selectNode/deselectNode
  • selectAll/deselectAll
  • getSelectedNodes
  • refreshTreeView

Usage

1.Reference the library from your module's build.gradle:

implementation 'me.texy.treeview:treeview_lib:1.0.6'

2.Implement your all level's BaseNodeViewBinder

Sample:

public class FirstLevelNodeViewBinder extends BaseNodeViewBinder {
  TextView textView;
  public FirstLevelNodeViewBinder(View itemView) { 
    super(itemView);  
    textView = (TextView) itemView.findViewById(R.id.node_name_view)
  }
  
  @Override
  public int getLayoutId() {
    return R.layout.item_first_level;
  }
  
  @Override
  public void bindView(TreeNode treeNode) {
    textView.setText(treeNode.getValue().toString());
  }
}

SecondLevelNodeViewBinder
ThirdLevelNodeViewBinder
.
.
.

If you want add the selectable feature,replace BaseNodeViewBinder with CheckableNodeViewBinder.

3.Implement the BaseNodeViewFactory

Sample:

public class MyNodeViewFactory extends BaseNodeViewFactory {
  @Override
  public BaseNodeViewBinder getNodeViewBinder(View view, int level) {
    switch (level) {
      case 0:
        return new FirstLevelNodeViewBinder(view);
      case 1:
        return new SecondLevelNodeViewBinder(view);
      case 2:
        return new ThirdLevelNodeViewBinder(view);
      default:
        return null;
    }
  }
}

If you do not want to create a class file,just implement a anonymous inner class in TreeView's constructor

4.Add TreeView to wherever you want

Sample:

TreeNode root = TreeNode.root();
//build the tree as you want
for (int i = 0; i < 5; i++) {
  TreeNode treeNode = new TreeNode(new String("Child " + "No." + i));
  treeNode.setLevel(0);
  root.addChild(treeNode);
}
View treeView = new TreeView(root, context, new MyNodeViewFactory()).getView();
//add to view group where you want 

License

   Copyright 2017 shineM.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

treeview's People

Contributors

alxkay avatar ivan200 avatar shinem avatar tomasjohansson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

treeview's Issues

加载数据卡顿

公司做压测,造了很多的数据,现在的情况是在设置数据的时候会卡住,滑动的时候没有问题,我想问下可能的原因在哪里?

selectNode()节点选中不可用

我使用发现,全选能用,但貌似单选有问题,selectNode()方法无效,另外selectNode()方法的adapter未实例化,在getView()后会实例化,但在这时候貌似无作用

在Binder里获取TextView总是闪退,find得到的为null。。。。

class FirstLevelBinder: BaseNodeViewBinder {
    var tv: TextView
    var root: LinearLayout

    constructor(view: View):super(view){
        tv = view.find(R.id.mem_group_title)//这里闪退。。。
        root = view.find(R.id.groupRoot)
    }

    override fun getLayoutId(): Int {
        return R.layout.ll_member_goods_group
    }

运行项目就报错了 Error

android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at me.texy.treeview.TreeViewAdapter.onCreateViewHolder(TreeViewAdapter.java:101)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6073)

支持数据异步加载吗?

类似于 #9 但不需要一直更新
我们用树来显示用户信息 可能有10万 分6到7层 bs使用的ztree实现的
每点击展开一层 请求网络数据
不知道如何添加点击事件 请指教

点击事件问题

最子项列表中的每个项的点击事件怎么响应啊?在bindView里也监听不到,没有position参数,没法确定点的是哪个子项
public class ThirdLevelNodeViewBinder extends CheckableNodeViewBinder {
TextView textView;

public ThirdLevelNodeViewBinder(View itemView) {
    super(itemView);
    textView = (TextView) itemView.findViewById(R.id.node_name_view);
}

@Override
public int getCheckableViewId() {
    return R.id.checkBox;
}

@Override
public int getLayoutId() {
    return R.layout.item_third_level;
}

@Override
public void bindView(final TreeNode treeNode) {
    textView.setText(treeNode.getValue().toString());
    Log.e("---ThreeTextView", treeNode.getValue().toString());
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //当点开二级列表的时候,三级列表有几个子项,此方法就会执行几遍
           Log.e("---ThreeTextView", treeNode.getValue().toString());
        }
    });
}

}

发现一个bug

在创建树(示例代码中的buildtree函数中)的过程中,如果设置children全选,children可以全选,但是parent不会自动全选。

android 4.4.2 闪退

安装不了
Could not find method android.view.Window.setStatusBarColor, referenced from method me.texy.treeviewdemo.MainActivity.setLightStatusBar
Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering

长按事件怎么设?

我看你TreeViewAdapter里有设onclick,但没longClick,在自己的NodeViewBinder这一层能设监听吗

提供单选模式么

最近用到这个树形列表,需要实现单选功能。具体需求是父节点和子节点单选要互斥。。就是选了父节点,子节点不全选中。怎么实现???

android O不兼容

将项目的 Targetversion26,报这个错误Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper;

如果不知道有多少子节点呢

比如不知道有多少层(根据网络进行请求,有子节点就返回数据进行展示,没有就结束),也就不能通过switch来判断,也就不能新建子节点的viewbinder,萌新问一下大佬这个该怎么处理。thanks。

子view

子view如果是九宫格怎么办

两个问题,请尽快回复,比较着急。谢谢

1,我的展开合上的图标在展开的时候没有反应,没看到相关代码,
2,最小层的点击事件如何实现,没有看到相关代码,没有相关说明。
麻烦大兄弟快点回复我,真的谢谢了。

请教个问题\(^o^)/~

demo里面都是自己造好数据,通过一个for循环,把组分好了,然后填充到Adapter中,我目前在项目中,需要自己分组,然后设置对应树形结构.例如我通过map把一组数据里面相同的name来进行分组,来做成这种结构的数据 List<String,List>那么再来一个person数据,在adapter里面我怎么只更新某个name下面的child,也就是怎么只更新parent下面的child类呢?

Is this library support tri-state checkbox?

Now if I select parent, all child will be selected and if I unselect one child parent selection will go off. Is there any way to show tri-state checkbox at that time for parent if any one child is selected.

How to delete all treenode and refill data again ?, i am using retrofit data to get data and when i am swiperefresh the data is double

public void getListProductCatalog() {
ll_productcatalog.setVisibility(View.GONE);
tv_emptyproductcatalog.setVisibility(View.VISIBLE);
tv_emptyproductcatalog.setText("Loading...");
srl_refresh_productcatalog.setRefreshing(true);

    apiServiceEndPointMIS.getListProductCatalog(misApplication.getSessionManager().getToken())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe(new Observer<Response<ListProductCatalogResponse>>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(Response<ListProductCatalogResponse> listProductCatalogResponseResponse) {
                    if (listProductCatalogResponseResponse.code() == 200) {
                        srl_refresh_productcatalog.setRefreshing(false);
                        if (listProductCatalogResponseResponse.body().isStatus()) {

                            if (listProductCatalogResponseResponse.body().getData() != null && listProductCatalogResponseResponse.body().getData().size() > 0) {
                                ll_productcatalog.setVisibility(View.VISIBLE);
                                tv_emptyproductcatalog.setVisibility(View.GONE);

                                if (listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog() != null && listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().size() > 0){
                                    for (int i = 0; i < listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().size(); i++) {
                                        TreeNode treeNode = new TreeNode(new String(listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getCompany().getCompany_id()+
                                                " - "+listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getCompany().getCompany_name()));
                                        treeNode.setLevel(0);
                                        for (int j = 0; j < listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().size(); j++) {
                                            TreeNode treeNode1 = new TreeNode(new String(listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_sdm_id()+
                                                    " - "+listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_sdm_name()));
                                            treeNode1.setLevel(1);
                                            for (int k = 0; k < listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().size(); k++) {
                                                TreeNode treeNode2 = new TreeNode(new String(listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_prt_id()+
                                                        " - "+listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_prt_name()));
                                                treeNode2.setLevel(2);
                                                for (int l = 0; l < listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_sdm_sub().size(); l++) {
                                                    TreeNode treeNode3 = new TreeNode(new String(listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_sdm_sub().get(l).getPrd_sdm_sub_id()+
                                                            " - "+listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_sdm_sub().get(l).getPrd_sdm_sub_name()));
                                                    treeNode3.setLevel(3);
                                                    for (int m = 0; m < listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_sdm_sub().get(l).getProduct().size(); m++) {
                                                        TreeNode treeNode4 = new TreeNode(new String(listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_sdm_sub().get(l).getProduct().get(m).getPrd_id()+
                                                                " - "+listProductCatalogResponseResponse.body().getData().get(0).getProduct_catalog().get(i).getPrd_sdm().get(j).getPrd_prt().get(k).getPrd_sdm_sub().get(l).getProduct().get(m).getPrd_name()));
                                                        treeNode4.setLevel(4);
                                                        treeNode3.addChild(treeNode4);
                                                    }
                                                    treeNode2.addChild(treeNode3);
                                                }
                                                treeNode1.addChild(treeNode2);
                                            }
                                            treeNode.addChild(treeNode1);
                                        }
                                        root.addChild(treeNode);
                                    }
                                }

                                treeView = new TreeView(root, ProductCatalogActivity.this, new MyNodeViewFactoryProductCatalog());
                                treeView.setItemAnimator(new DefaultItemAnimator());
                                View view = treeView.getView();
                                view.setLayoutParams(new ViewGroup.LayoutParams(
                                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                                viewGroup.addView(view);

                                treeView.expandAll();

                            } else {
                                ll_productcatalog.setVisibility(View.GONE);
                                tv_emptyproductcatalog.setVisibility(View.VISIBLE);
                                tv_emptyproductcatalog.setText("Empty Data");
                            }

                        } else {
                            ll_productcatalog.setVisibility(View.GONE);
                            tv_emptyproductcatalog.setVisibility(View.VISIBLE);
                            tv_emptyproductcatalog.setText("Session time out, please re-login!");
                            misApplication.showToast("Session time out, please re-login!");
                        }

                    } else {
                        srl_refresh_productcatalog.setRefreshing(false);
                        ll_productcatalog.setVisibility(View.GONE);
                        tv_emptyproductcatalog.setVisibility(View.VISIBLE);
                        tv_emptyproductcatalog.setText("There is a problem with the internal server, please contact support application!");
                        misApplication.showToast("There is a problem with the internal server, please contact support application!");
                    }
                }

                @Override
                public void onError(Throwable e) {
                    srl_refresh_productcatalog.setRefreshing(false);
                    System.out.println("ERROR" + e.getMessage());
                    ll_productcatalog.setVisibility(View.GONE);
                    tv_emptyproductcatalog.setVisibility(View.VISIBLE);
                    tv_emptyproductcatalog.setText("An error occurred, check your internet connection again!");
                    misApplication.showToast("An error occurred, check your internet connection again!");
                }

                @Override
                public void onComplete() {

                }
            });
}

image

I got NoClassDefFoundError when clicking the items

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper;
at me.texy.treeview.animator.DefaultItemAnimator.resetAnimation(DefaultItemAnimator.java:520)
at me.texy.treeview.animator.DefaultItemAnimator.animateMove(DefaultItemAnimator.java:256)
at android.support.v7.widget.SimpleItemAnimator.animatePersistence(SimpleItemAnimator.java:126)
at android.support.v7.widget.RecyclerView$4.processPersistent(RecyclerView.java:504)
at android.support.v7.widget.ViewInfoStore.process(ViewInfoStore.java:241)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3444)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3194)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3627)

数据刷新的问题

第一次加载数据生成一个树形的列表了,然后点击搜索,重新请求数据,如何把第一次的树列表删除,重新生成新数据的树列表??还有一个问题就是第二级含有RadioGroup与Radio时,选择第二个一级菜单的item会覆盖第一个一级的值,获取到的下标值不正确。求指教

数据加载

大神 请教个问题 假如层级很多 数据也很多 不能一次性加载 该如何实现

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.