本文介绍了定制黑莓Treefield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要定制的树视图左侧出现的(+)号
是否可以
我希望把图像在那个地方

I want to customise the (+) sign that appears on the left side of tree viewIs it possibleI want to place image in that place

我曾尝试定制和搜索的论坛也黑莓论坛,其中一人表示,其不可能的但结果
我得到这个如下一个链接,说,这是可能的。

i have tried to customise and searched the forums also Blackberry forums where one of them said its not possible but then
i got a link for this As below which says it is possible

其中HardwareDevice类似乎缺少

where the HardwareDevice class seems to be missing

使用链接的还是自己的任何其他答案谁能解释这个概念
请建议?

Can anyone explain this concept using the link or any other answer of their ownPlease suggest ?

推荐答案

[ 更新时间:]如果你想为自定义的(+)的一 TreeField 而不是写你自己的树领域,然后你可以尝试重新写 drawTreeItem 方法href=\"http://docs.blackberry.com/en/developers/deliverables/6022/net/rim/device/api/ui/component/TreeFieldCallback.html\"相对=nofollow> TreeFieldCallback 如下所示:

[UPDATED] If you want to CUSTOMISE the (+)-sign and other attributes of each row of a TreeField rather than writing your own tree field then you can try re-writing the drawTreeItem method of TreeFieldCallback like shown below:

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.TreeField;
import net.rim.device.api.ui.component.TreeFieldCallback;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class TreeDemo extends MainScreen {
    int parent[] = {1,2,3,4,5,6,7,8,9};
    int child[][] = new int [10][10];
    int child_child[][][] = new int [10][10][10];

    int rowHeight = 27;

    CustomTreeFieldCallback treeCallback = new CustomTreeFieldCallback();
    VerticalFieldManager vm = new VerticalFieldManager(Field.FOCUSABLE | VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
    TreeField myTree = new TreeField(treeCallback, Field.FOCUSABLE);

    public TreeDemo() {
        vm.add(new LabelField("Table:"));
        myTree.setRowHeight(rowHeight);
        myTree.setIndentWidth(15);
        myTree.setDefaultExpanded(false);
        for(int i = parent.length-1; i >= 0 ; i--) {
            parent[i] = myTree.addChildNode(0, "Parent_" + (i+1));
            child[i] = new int[4];
            for(int j = child[i].length-1; j >=0 ; j--) {
                child[i][j] = myTree.addChildNode(parent[i], "Child_"+ (i+1) + "_" + (j+1));
                child_child[i][j] = new int[3];
                for(int k = child_child[i][j].length-1; k >= 0 ; k--) {
                    child_child[i][j][k] = myTree.addChildNode(child[i][j], "Child_of_Child_"+ (i+1) + "_" + (j+1)+ "_" + (k+1));
                }
            }
        }
        vm.add(myTree);
        add(vm);
    }

    private class CustomTreeFieldCallback implements TreeFieldCallback {

        public void drawTreeItem(TreeField treeField, Graphics graphics, int node,
                int y, int width, int indent) {
            // TODO Auto-generated method stub
            String string = (String) treeField.getCookie(node);
            int preservedColor = graphics.getColor();

            if(treeField.getCurrentNode() == node) {
                graphics.setColor(0x0CCCC0);
            } else {
                graphics.setColor(0x404040);
            }
            graphics.fillRect(0, y, Display.getWidth(), treeField.getRowHeight());

            Bitmap iconImage;
            int iconImageWidth = 0;
            indent -= 20; // decrease the extra indentation for all nodes.
            if(treeField.getFirstChild(node) != -1){ // if the node is not a leaf node
                if(treeField.getExpanded(node)) {
                    iconImage = Bitmap.getBitmapResource("icon_arrow_down.png");
                    iconImageWidth = iconImage.getWidth();
                } else {
                    iconImage = Bitmap.getBitmapResource("icon_arrow_right.png");
                    iconImageWidth = iconImage.getWidth();
                }
                graphics.drawBitmap(indent, y, indent+iconImageWidth, treeField.getRowHeight(), iconImage, 0, 0);
            }

            if( treeField.getCurrentNode() == node ) {
                graphics.setColor(0x404040);
            } else {
                graphics.setColor(0x0CCCC0);
            }
            graphics.drawText(string, indent+iconImageWidth, y);

            graphics.setColor(preservedColor);
        }

    }
}

这篇关于定制黑莓Treefield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:45