Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 15
Registered: ‎05-07-2009
My Device: Not Specified

strange behaviour with tree field

Hello,

 

  I have been noticing some strange behaviour with a tree field I am populating.  What I am doing is creating a vector of strings, then sorting the vector (A--->Z).  When I add the vector to the tree field as child nodes, I see that it is being processed correctly (ie. in the sorted order), but when it shows up on the screen, it is in reverse order.

 

  I do not see what is causing the display to be reversed from the original sort order.  I have checked and double checked everything and everything looks okay.  I cannot see anything I can set on the tree field that would allow me to control the order....but it should just be controlled by the node I am putting the value into.

 

Just wondering if anyone has ever come across this situation before?

 

Thanks

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: strange behaviour with tree field

I get this problem some time ago.

 

Use your sorted vector in TreeFieldCallback implementation and add elements from that vector in reverse order to the tree field.

 

int maxIndex = vector.size()-1;

for (int i=maxIndex; i>=0; i--)  {

   Object element = vector.elementAt(i);

 

   // add to tree field

}

 

 

 

New Developer
Posts: 15
Registered: ‎05-07-2009
My Device: Not Specified

Re: strange behaviour with tree field

previous suggestion works, along with just sorting in reverse order.  Still do not understand the reason for the behaviour though.  Wonder if it has to do with the number of child nodes there are...

 

set up as follows

 

Parent

 

   child_1

       child_2

            child_3

            siblings to child_3

 

       siblings  to child_2

   siblings to child_1

      etc.

 

 

then repeated n times.

 

Wonder if some counter/positioning is mixed up internally?

 

     

 

New Contributor
Posts: 8
Registered: ‎01-05-2011
My Device: 8330

Re: strange behaviour with tree field

I have the same problem. I am parsing xml using DOM parser and adding the nodes to tree field. Nodes are added properly in the tree field but when the tree field displays on the screen they are in the reverse order. This is happened since value of node parameter in the drawTreeItem() method is wrong.

Is there any way to set the proper value for the node parameter?

Regards,
Medha

New Contributor
Posts: 3
Registered: ‎01-19-2013
My Device: BlackBerry Curve 9300
My Carrier: Virgin

Re: strange behaviour with tree field

[ Edited ]

I have found that if you use addSiblingNode instead of addChildNode the ordering is correct, e.g.

 

String fieldOne =new String("Parent folder 1");

String fieldTwo = new String("Parent folder 2");

int node1 = treeField.addChildNode(0, fieldOne);

int node2 = treeField.addSiblingNode(node1, fieldTwo);

 

This code will then display Parent folder 1 followed by Parent folder 2