dingyi222666 / TreeView

An Android TreeView with RecyclerView
Apache License 2.0
109 stars 10 forks source link

How can I disable to collapse of root node? #7

Closed lijingdoc closed 1 year ago

lijingdoc commented 1 year ago

Thanks for your great library.

I need your help. I want to disable to collapse of the root node. It means that the root node should be expanded forever. Is there any way?

Thanks

lijingdoc commented 1 year ago

@dingyi222666 Could you help me?

dingyi222666 commented 1 year ago

I don’t have time to develop TreeView recently. I may have to wait a few weeks before I can continue developing.

dingyi222666 commented 1 year ago

Ok. This is a simple question. First, let's expand the root node list when initializing the tree.

treeview.expandUntil(1,true)
// or expandAll
treeview.expandAll(true)

Then you need to implement the TreeViewBinder and override the onToggle method.

The onToggle method run after the default action (like expanding or collapsing a node), so you just need to check if the node is the root node in this method, and then set it to force expand.

override fun onToggle(
            node: TreeNode<DataSource<String>>,
            isExpand: Boolean,
            holder: TreeView.ViewHolder
        ) {
    if (node.depth < 1) {
        node.expand = true
    }
}
lijingdoc commented 1 year ago

Hi, @dingyi222666 It works well, thanks so much.