AndroidTreeView icon indicating copy to clipboard operation
AndroidTreeView copied to clipboard

Clear a node's children

Open muhammad-naderi opened this issue 10 years ago • 6 comments

Hi,

My main tree got couple of main nodes, and a node which contains the last used leafs. so whenever the fragment containing the treeView reloads I need to clear the last used node and repopulate it with my logic.

the problem is when I do a foreach loop on treenode.getChildren() and call treeNode.deleteChild(tNode); I get java.util.ConcurrentModificationException

any idea on how to do this ?

I also tried to remove the treeNode itself and re add it, but it is a bit buggy, because the re added node, although is not expanded in the UI, but for the first time, it needs two touches to get expanded.

muhammad-naderi avatar Nov 30 '15 05:11 muhammad-naderi

well that problem resolved by copying the getChildren list and do the loop on the copy,

after changing the node's children, it seems that the tree does not sense the modification, and does not show the new list. is there any way to accomplish this? something like adapter.notifyDataSetChanged() or so ?

muhammad-naderi avatar Nov 30 '15 06:11 muhammad-naderi

apparently collapsing and then expanding the node does the trick, but I'm sure it's gotta be a cheaper way to do this as well, or at least it is better to be...

muhammad-naderi avatar Nov 30 '15 07:11 muhammad-naderi

I think you are right I should add something like notifyDataSetChanged(), unfortunately after view is rendered it's not going to be updated after model is updated. I will add this in next version Thanks

bmelnychuk avatar Dec 01 '15 09:12 bmelnychuk

Hi,

I was wondering if there is any update on this matter.

I'm currently trying to update a mid-level TreeNode by deleting it, and adding a new updated object. I save the children in a temp List<> and add them to the new object and re-toggle the parent node. However, I get a The specified child already has a parent. You must call removeView() on the child's parent first. exception when I click the new object.

private void updateTreeItem(TreeNode item, Category newValues){ TreeNode parentItem = item.getParent(); List<TreeNode> childes = item.getChildren(); mTreeView.toggleNode(parentItem); parentItem.deleteChild(item); item = new TreeNode(newValues).setViewHolder(new TreeViewItem(getContext())); item.addChildren(childes); parentItem.addChild(item); mTreeView.toggleNode(parentItem); }

Any idea on how to solve this?... at least till the next update

doruchidean-lifeishard avatar Oct 13 '16 09:10 doruchidean-lifeishard

I think you have to delete the list from the end to the beginning like

for (int i = mNode.getChildren().size(); i >= 0; i--) { mNode.getChildren().remove(i); }

This is because of the structure of a list. Each item contains its next item, and if you remove it, you can't access its next anymore, so you have to delete it from the tail to the head.

LukasJue avatar Oct 13 '16 21:10 LukasJue

Any news about clear all children?)

geminixandroid avatar Oct 06 '17 10:10 geminixandroid