我在blackberry java app中设计了一个简单的树视图。现在我需要在子节点中添加一个图像。
有可能吗?
答案 0 :(得分:0)
找到这段代码
class TreefieldDemoScreen extends MainScreen
{
public TreefieldDemoScreen()
{
setTitle("Tree Field with icon");
String parentNode = new String("Parent");
String firstChild = new String("first child");
String secondChild = new String("second child");
String thirdChild = new String("third child");
TreeCallback myCallback = new TreeCallback();
TreeField myTree = new TreeField(myCallback, Field.FOCUSABLE);
int node2 = myTree.addChildNode(0, parentNode);
myTree.addChildNode(node2, firstChild);
myTree.addChildNode(node2, secondChild);
myTree.addChildNode(node2, thirdChild);
add(myTree);
}
private class TreeCallback implements TreeFieldCallback
{
public void drawTreeItem(TreeField _tree, Graphics g, int node, int y, int width, int indent)
{
String text = (String)_tree.getCookie(node);
Bitmap b=Bitmap.getBitmapResource("icon_bb copy.png");
g.drawText(text, indent+b.getWidth(), y);
g.drawBitmap(indent, y, b.getWidth(), b.getHeight(), b, 0, 0);
}
}
}