Parent Node or Child Node in Blackberry Tree Field?

我只是一个虾纸丫 提交于 2020-01-05 09:09:03

问题


I need to traverse a Tree Field in Blackberry . I need to know how to check from the existing node whether it is a parent node or child node ? Since I need a different row color for Child rows and Parent rows

I have referred a previous question of Customising TreeField as seen in link below

Customising Blackberry Treefield


回答1:


It looks like you're already using the TreeFieldCallback to customize painting of your tree field. You can detect parent vs. child nodes here in drawTreeItem().

However, we need to be clear about what you consider "parent" and "child", because technically, it's possible for a row to be both a parent and a child, if the tree has more than 2 levels (in addition to the root level).


If "Child" == "Leaf" Node

Use:

public void drawTreeItem(TreeField treeField, Graphics graphics, int node, int y, int width, int indent)  {

    boolean isChild = treeField.getFirstChild(node) == -1;
    if (isChild) {
        // draw child row color
    } else { 
        // draw parent row color
    }
} 

assuming that what you mean by "child" is a row that has no more children of its own (also called a "leaf" node).


If "Child" == "Non-Root Parent"

If you consider a node that has both a non-root parent of its own and a child of its own to be a "child" row, then use this logic:

public void drawTreeItem(TreeField treeField, Graphics graphics, int node, int y, int width, int indent)  {

    boolean isParent = treeField.getParent(node) == 0;
    if (isParent) {
        // draw parent row color
    } else { 
        // draw child row color
    }
}

this second implementation will only color rows that are directly under the root node as "parents".



来源:https://stackoverflow.com/questions/17723328/parent-node-or-child-node-in-blackberry-tree-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!