AndroidTreeView——无限层级的Android树视图

一款实现树视图的Android类库,实现树叶子无限层级展开/折叠,可以定义节点的值、视图、样式,还可以在屏幕旋转后保持状态不变。
 
用法:
 
1、创建树根节点
TreeNode root = TreeNode.root();
2、创建和添加加点(使用自定义对象作为构造函数参数)
 TreeNode parent = new TreeNode("MyParentNode");
 TreeNode child0 = new TreeNode("ChildNode0");
 TreeNode child1 = new TreeNode("ChildNode1");
 parent.addChildren(child0, child1);
 root.addChild(parent);
3、将tree view添加到布局中
 AndroidTreeView tView = new AndroidTreeView(getActivity(), root);
 containerView.addView(tView.getView());
 
4、自定义节点视图
Extend TreeNode.BaseNodeViewHolder and overwrite createNodeView method to prepare custom view for node:
public class MyHolder extends TreeNode.BaseNodeViewHolder<IconTreeItem> {
    ...
    @Override
    public View createNodeView(TreeNode node, IconTreeItem value) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        final View view = inflater.inflate(R.layout.layout_profile_node, null, false);
        TextView tvValue = (TextView) view.findViewById(R.id.node_value);
        tvValue.setText(value.text);

        return view;
    }
    ...
    public static class IconTreeItem {
        public int icon;
        public String text;
    }
}

5、Connect view holder with node

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

6、Consider using

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

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页