BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-06-2007, 11:07 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2007
Location: India
Model: 8100
Carrier: Airtel
Posts: 64
Post Thanks: 0
Thanked 0 Times in 0 Posts
Post About TreeField

Please Login to Remove!

Hi All,

I'm new to Blackberry developement.
I want to develop a application using tree. I already done some implementation regarding this.

i want to add columns in front of each node. The columns may contain any value? And there are any number of columns.

My problem is that I can't able to add them. I tried it, but screen get flickerred when I scroll it.

Is anyone have any idea about what we can do for it?

Also, I want to change Text_color and background color of the node on which current focus is there. I could not able do it properly. So, also need help in this regard too,

Thanks
__________________
Crazy for BlackBerry
Offline  
Old 03-07-2007, 07:00 PM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Chinasaur's Avatar
 
Join Date: Apr 2006
Location: Portland/Seattle Megalopolis
Model: 8700g
Carrier: T-Mobile
Posts: 316
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

This would have been better if posted in the Developer forum. Hopefully a nice mod, or other dev, will wander in here and move it for you..or answer the question.

Luck!
Offline  
Old 03-07-2007, 07:05 PM   #3 (permalink)
Grumpy Moderator
 
NJBlackBerry's Avatar
 
Join Date: Aug 2004
Location: Somewhere in the swamps of Jersey
Model: i5s
Carrier: AT&T
Posts: 27,771
Post Thanks: 32
Thanked 439 Times in 379 Posts
Default

** Moving to the Developer's Forum **
Offline  
Old 03-08-2007, 08:41 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

it is not clear what columns do you mean. Can you post short code sample, which shows your problem?
Offline  
Old 03-09-2007, 06:42 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2007
Location: India
Model: 8100
Carrier: Airtel
Posts: 64
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question About Treefield

Hi all,

I want to display data as tree which is in xml file .

I'll show u for example as follows


Department
|
MSc
|
|- Physics
|
|- First year Sub1 Sub2 sub3
| |- stud1 50 60 58
| |- stud2 60 59 60
|-Second year Sub1 Sub2 Sub3
|

like this so on

Columns I'm talking about are subjects in above case. I haven't done any coding for that. But i need to code. So, I'm sorry to say I cn't give sample of code. here tree may increase.
Also , when I click any parent node AND if it collapses or expands according to that columns should be get hidden or shown. I want to know how can I do so. Plz help me out.

If anybody know plz let me know too.

Thanks
__________________
Crazy for BlackBerry
Offline  
Old 03-09-2007, 07:50 AM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

please, search "BlackBerry Application Developer Guide, Volume 1" for TreeField and TreeFieldCallback description. There is short chapter about it. You can implement TreeFieldCallback and draw anything you want.
Offline  
Old 03-13-2007, 07:50 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2007
Location: India
Model: 8100
Carrier: Airtel
Posts: 64
Post Thanks: 0
Thanked 0 Times in 0 Posts
Post About tree- field

Hi All,

i got the way to display tree along with table.

But, there is little problem, I got the tree but not in the order I want. Nodes are not in proper way.
First all parents are displayed then their children are shown. They are in order.
But I want order is that If 1st parent is displayed then after that it's all children should be shown then the parent among that children is shown.
E.g
there is tree with following node where P is parent and C is child
P1 - C1, C2, P2
P2 - C3, C4,P3
P3 - P4
P4 - C5, P5

The tree I want is like

P1
- c1
- c2
- p2
- - c3
- - c4
- - p3
- - - p4
- - - - c5
- - - - p5

But I got

P1
- p2
- - p3
- - - p4
- - - - p5
- - - - c5
- - c3
- - c4
- c1
- c2


Can anybody help me to make tree in correct order.

Thanks
__________________
Crazy for BlackBerry
Offline  
Old 03-13-2007, 08:00 AM   #8 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Renuka_anil,
Post your code here, perhaps we can figure out what's wrong.
Offline  
Old 03-20-2007, 12:04 AM   #9 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2007
Location: India
Model: 8100
Carrier: Airtel
Posts: 64
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default About Tree field

Hi

here is my whole code. I create a class in which tree is dynamically read from XML file generated.


public class CustomChart extends VerticalFieldManager{
// Declaration
private TreeCallback myCallback;
private TreeField myTree;
private boolean hasFocus; //false
private int[] nodeArray;
private int arrLength;
private Util objUtil ;

protected void sublayout(int maxWidth, int maxHeight){
maxWidth = 200 ;
maxHeight = 350;
super.sublayout(maxWidth, maxHeight);
}

//vecParent is vector for all parent node
//vecChild stores childs corresponding to that parent
// sizes is total number of nodes
// strTitle title for tree.

public CustomChart(String strTitle, Vector vecParent, Vector vecChild, int sizes ) {
super(Manager.HORIZONTAL_SCROLL | Manager.VERTICAL_SCROLL);
try{
objUtil = new Util();
//_screen = new MainScreen();
sizes = sizes + 1;
nodeArray = new int[sizes];
myCallback = new TreeCallback();
myTree = new TreeField(myCallback, Field.FOCUSABLE){
//Handles moving the focus within this field.
/* public int moveFocus(int amount, int status, int time)
{
invalidateNode(getCurrentNode());
return super.moveFocus(amount,status,time);
//return true;
}*/

//Invoked when this field receives the focus.
/* public void onFocus(int direction)
{
hasFocus = true;
//super.onFocus(direction);
}

//Invoked when a field loses the focus.
public void onUnfocus()
{
hasFocus = false;
//super.onUnfocus();
invalidate();
}
*/
//Over ride paint to produce the alternating colours.
/* public void paint(Graphics graphics)
{
//Get the current clipping region as it will be the only part that requires repainting
XYRect redrawRect = graphics.getClippingRect();
if(redrawRect.y < 0)
{
throw new IllegalStateException("Clipping rectangle is wrong.");
}

//Determine the start location of the clipping region and end.
int rowHeight = getRowHeight();

int curSelected;

//If the ListeField has focus determine the selected row.
if (hasFocus)
{
curSelected = getCurrentNode();
}
else
{
curSelected = -1;
}

int startLine = redrawRect.y / rowHeight;
int endLine = (redrawRect.y + redrawRect.height - 1) / rowHeight;
endLine = Math.min(endLine, getNodeCount() - 1);
int y = startLine * rowHeight;

//Setup the data used for drawing.
int[] yInds = new int[]{y, y, y + rowHeight, y + rowHeight};
int[] xInds = new int[]{0, getPreferredWidth(), getPreferredWidth(), 0};

//Get the ListFieldCallback.
//This sample assumes that the object returned by the get
//method of the callback is a String or has a toString method.
//If this is not the case you will need to add the required logic
//for your implementation.



//Draw each row
for(; startLine <= endLine; ++startLine)
{
if (startLine % 2 == 0 && startLine != curSelected)
{
//Draw the even and non selected rows.
graphics.setColor(LIGHT_TEXT);
graphics.drawShadedFilledPath(xInds, yInds, null, cols, null);
graphics.drawText((String)getCookie(startLine), 0, yInds[0]);
graphics.setColor(DARK_TEXT);
}
else
{
//Draw the odd or selected rows.
graphics.drawText((String)getCookie(startLine), 0, yInds[0]);
}

//Assign new values to the y axis moving one row down.
y += rowHeight;
yInds[0] = y;
yInds[1] = yInds[0];
yInds[2] = y + rowHeight;
yInds[3] = yInds[2];
}
}*/
};
int c = 0;
int j = 0;

String[] strSplit = null;
boolean flgParent = false;

String strTemp = null;

for(int i = 0; i < vecParent.size(); ){
int tmp = i;
tmp = tmp + 1;
boolean flag = true;
String strParent = (String) vecParent.elementAt(i);
String strChild = (String)vecChild.elementAt(i);
strSplit = objUtil.splitMethod(strChild, ',');
for(int cnt = 0; cnt < strSplit.length; cnt++){
if(strSplit[0].equals("0") && flag == true){
if(j == 0){
//j = j + 1;
nodeArray[j] = myTree.addChildNode(0,strParent);
c = j;
flag = false;
} else {
//j = j + 1;
nodeArray[j] = myTree.addChildNode(0,strParent);
c = j;
flag = false;
}
}else{
if(tmp < vecParent.size()){
strTemp = (String)vecParent.elementAt(tmp);
//System.out.println(" strTemp "+strTemp);
}

if(strSplit[cnt].equalsIgnoreCase(strTemp)){
strParent = strTemp;
nodeArray[j] = myTree.addChildNode(nodeArray[c],strParent);
c = j;
flgParent = true;
i = i + 1;
}else{
nodeArray[j] = myTree.addChildNode(nodeArray[c],strSplit[cnt]);
flgParent = false;
}

}
j = j + 1;
}
if( flgParent == false)
i = i + 1;
flag = true;
}


add(new LabelField (
strTitle , LabelField.NON_FOCUSABLE | LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH
));

add(myTree);

}catch(Exception e){
System.out.println("Exception in buiding chart : "+e.toString());
}// end of try-catch
}// end of constructor.


private class TreeCallback implements TreeFieldCallback {
Util objUtils;

private TreeCallback(){
objUtils = new Util();
}
public void drawTreeItem(TreeField _tree, Graphics g, int node, int y, int width, int indent) {
String text = (String)_tree.getCookie(node);
indent = indent + 5;
int row = _tree.getCurrentNode();
objUtils.setCurrentRow(row);
//System.out.println(" strParent "+text);
g.drawText(text, indent, y);
}
}
}// end of class



Please check this out. And tell me what's wrong with this. Also, can u tell me how to change textcolor and background color for current node having focus on it. Also how to add bitmaps for parent and child. Parent has different bitmaps than child


Thanks
__________________
Crazy for BlackBerry
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.