父节点或子节点的黑莓树现场? [英] Parent Node or Child Node in Blackberry Tree Field?
问题描述
我需要黑莓遍历树现场。
我需要知道如何从现有的节点是否是父节点或子节点检查?
因为我需要为孩子行和父行不同的行颜色
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
我已经提到定制TreeField的previous问题为纽带看到下面
I have referred a previous question of Customising TreeField as seen in link below
推荐答案
它看起来像你已经在使用 TreeFieldCallback
自定义您的树领域的绘画。您可以检测父与孩子<一个节点这里href=\"http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/component/TreeFieldCallback.html#drawTreeItem%28net.rim.device.api.ui.component.TreeField,%20net.rim.device.api.ui.Graphics,%20int,%20int,%20int,%20int%29\"相对=nofollow> drawTreeItem()。
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().
但是,我们必须清楚你认为什么是父与子,因为从技术上讲,有可能为一排为两个的父母和一个孩子,当树超过2级(除了根级)。
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).
使用:
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 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".
这篇关于父节点或子节点的黑莓树现场?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!