AndroidTreeView icon indicating copy to clipboard operation
AndroidTreeView copied to clipboard

expand/collapse Node

Open Neha1405 opened this issue 7 years ago • 2 comments

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.

Neha1405 avatar Dec 31 '17 11:12 Neha1405

You can keep a reference to that node, and use a depth first search to find it back and apply your expand to it.

maxime-kouemo avatar Jan 19 '18 12:01 maxime-kouemo

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 ;
        }
    }    

ProFive avatar Mar 12 '18 03:03 ProFive