marinat / tree-view-list-android

Automatically exported from code.google.com/p/tree-view-list-android
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Duplicate nodes under different parents #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add more than one node with the same name.

What is the expected output? What do you see instead?
If the nodes were under different parents I would expect no problem.

What version of the product are you using? On what operating system?
29April2012

Please provide any additional information below.
If you add two nodes of the same name, the second node will fail, regardless of 
if the node exists under another parent.  I would expect repeat names under 
different parents to be acceptable.

I'm looking into fixing this now.

Original issue reported on code.google.com by AMan...@gmail.com on 1 Aug 2012 at 8:54

GoogleCodeExporter commented 9 years ago
The current solution can support this without any modification, it just 
requires a little ingenuity on the user-end.  Here's what I did:

1) Create a parent-child pair object.  This serves as a unique identifier.

        public class ParentChild<T>
        {
         private T parent;
         private T child;
         public ParentChild(T parent, T child)
...

2) When building your tree use the pair as the node:

        ParentChild pair = new ParentChild(parents.get(level-1), node);
    tree.sequentiallyAddNextNode(pair, level);

3) Ensure you pull the child from the pair for purposes of display in your 
adapter:

        String name = (String)((ParentChild)treeNodeInfo.getId()).getChild();
        descriptionView.setText(name);
...
        final CheckBox box = (CheckBox) viewLayout.findViewById(R.id.demo_list_checkbox);
        box.setTag(name);

Kudos for a design that still allowed this.  Perhaps this was the intention all 
along?  In which case I would update the 'T' definition in comments to specify 
UNIQUE identifier.  That way it's a little more clear what should go in there, 
and make this solution more obvious.  Thanks for the code!

Original comment by AMan...@gmail.com on 2 Aug 2012 at 3:00

GoogleCodeExporter commented 9 years ago
Thanks for the comment and investigation! 

The id's were supposed to be unique across the whole tree indeed. I added that 
in the comment now - I hope it will be clear to all the future devs using it :).

Original comment by ja...@potiuk.com on 18 Aug 2012 at 10:11