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
Highlighted
New Developer
Posts: 37
Registered: ‎03-31-2009
My Device: Not Specified
Accepted Solution

TreeField and child of Treefield?

Hi all, quick question! Can a TreeField be set as a node/child of a parent TreeField?
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: TreeField and child of Treefield?

I don't think it can be!
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: TreeField and child of Treefield?

[ Edited ]

If you want a system like tree inside a tree, then the following code should help..

 

 

import net.rim.device.api.ui.Graphics;

import net.rim.device.api.ui.UiApplication;

import net.rim.device.api.ui.component.TreeField;

import net.rim.device.api.ui.component.TreeFieldCallback;

import net.rim.device.api.ui.container.MainScreen;

public class MyApp extends UiApplication {

TreeCallback _myCallback;

TreeField _myTree;

public static void main(String[] args) {

MyApp app = new MyApp();

app.enterEventDispatcher();

}

public MyApp()

{

String fieldOne = "Main Folder2";

String fieldTwo = "Main Folder1";

String fieldThree = "SubFolder3";

String fieldFour = "SubFolder2";

String fieldFive= "SubFolder1";

_myCallback = new TreeCallback();

_myTree = new TreeField(_myCallback, TreeField.FOCUSABLE);

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

int node2 = _myTree.addChildNode(0, fieldTwo);

int node3 = _myTree.addChildNode(node1, fieldThree);

int node4 = _myTree.addChildNode(node3, fieldFour);

int node5 = _myTree.addChildNode(node3, fieldFive);

MainScreen mainScreen = new MainScreen();

mainScreen.add(_myTree);

pushScreen(mainScreen);

}

public static class TreeCallback implements TreeFieldCallback {

public void drawTreeItem (TreeField tree, Graphics g, int node, int y, int width, int indent) {

Object obj = tree.getCookie(node);

if (obj instanceof String)

{

String text = (String)obj;

g.drawText(text, indent, y);

}

}

}

}

 

 

 

 

Thanks!

 

 

Message Edited by mantaker on 04-02-2009 02:45 PM
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
New Developer
Posts: 37
Registered: ‎03-31-2009
My Device: Not Specified

Re: TreeField and child of Treefield?

that works perfectly, thank you!
New Developer
Posts: 37
Registered: ‎03-31-2009
My Device: Not Specified

Re: TreeField and child of Treefield?

just to try something different, I replaced

 

 

String fieldFive= "Subfolder1";

 

 with

 

CheckboxField fieldFive = new CheckboxField("Task 1", true);

 

 it compiles and runs on the sim fine. everything shows up but not the checkbox. any ideas?

 

 

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: TreeField and child of Treefield?

What is showing up in that place?
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
New Developer
Posts: 37
Registered: ‎03-31-2009
My Device: Not Specified

Re: TreeField and child of Treefield?

just a blank field. it's focusable, and when clicked opens a basic menu, but there is no text or checkbox.
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: TreeField and child of Treefield?

Just checked that in my simulator also..

 

Lemme try some possibilities.. But this is 95% un-achievable Smiley Tongue 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
New Developer
Posts: 37
Registered: ‎03-31-2009
My Device: Not Specified

Re: TreeField and child of Treefield?

I'm feeling lucky! or my whole app idea is out the window!
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: TreeField and child of Treefield?

However you can use TreeField.getCurrentNode() for this purpose in a normal tree without checkbox :-/
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group