AndroidTreeView
AndroidTreeView copied to clipboard
expand/collapse Node
Hi , i've used this library and currently facing some issue regarding expand/collapse particular node. Can anyone suggest how can i collapse or expand any particular node excepting expanding all method. I mean once i collapsed/expand any node & then when i come back with tree view i need the same state of tha tree which were previously collapsed/expand.
You can keep a reference to that node, and use a depth first search to find it back and apply your expand to it.
Try it:
private void selectedObject(int objectId) {
getTreeNode(mModelTreeNode, objectId + "");
if (mNodeSelection != null) {
lstTreeNode.clear();
listTreeNode(mNodeSelection);
if(lstTreeNode.size() > 0) {
for (int i = lstTreeNode.size() - 1; i >= 0; i--) {
if (!lstTreeNode.get(i).isExpanded()) {
mModelTreeATV.expandNode(lstTreeNode.get(i));
}
}
}
}
}
List<TreeNode> lstTreeNode = new ArrayList<>();
private void listTreeNode(TreeNode treeNode) {
lstTreeNode.add(treeNode);
if (!treeNode.isRoot()) {
listTreeNode(treeNode.getParent());
}else{
return ;
}
}