gpt4 book ai didi

blackberry - 具有不同图像和可点击事件的父子节点 - Treeview Blackberry

转载 作者:行者123 更新时间:2023-12-04 04:43:55 28 4
gpt4 key购买 nike

我在应用程序中使用树 View 来显示黑莓中的客户端服务器数据。我通过使用可扩展的 ListView 项目在 android 应用程序中实现了同样的事情。但在这里我面临两个问题
一种是:
我想添加父节点图标,如文件夹图标 & 子节点必须有不同的图标。例如,如果父项是图像,则子节点必须具有图像图标,如果父项是视频,则子节点必须具有视频图标。
第二:
当我点击任何子节点(如图像子节点)时,该节点会在新屏幕中打开并显示可点击的项目,无论我点击图像还是视频。
这是我用来获得所需结果的代码:

class CustomTreeFieldCallback implements TreeFieldCallback {
public void drawTreeItem(TreeField _tree, Graphics g, int node, int y,
int width, int indent) {
// FontFamily
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 18);
g.setFont(font);
String text = (String) _tree.getCookie(node);
Bitmap b = Bitmap.getBitmapResource("images.png");
g.drawText(text, indent + b.getWidth(), y);
g.drawBitmap(indent, y - 15, b.getWidth(), b.getHeight(), b, 0, 0);
}
}

public class FilesManager extends MainScreen {

public FilesManager() {

// Set the linear background.
Bitmap background = Bitmap.getBitmapResource("background.png");
Background bg = BackgroundFactory.createBitmapBackground(background);
this.getMainManager().setBackground(bg);

String parentNode = new String("Images");
String firstChild = new String("first child");
String secondChild = new String("second child");
String thirdChild = new String("third child");

CustomTreeFieldCallback myCallback = new CustomTreeFieldCallback();
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);

}

}
我还附上了我在 android 中制作的屏幕截图。有没有人给我指导在 BB 中实现这件事?
enter image description here

最佳答案

你有一个好的开始。
要获得正确的图标,您只需要检测哪些树“节点”是文件夹、电影、歌曲、图像等。使用 TreeField#getFirstChild() 执行此操作即可。或者通过检查 cookie/text,对于每个节点,在 drawTreeItem() 内.
要处理对电影、图像或歌曲行的点击,override navigationClick() .
例如,以 the TreeFieldDemo from BlackBerry 开头:

class TreeFieldDemoScreen extends MainScreen
{

private final Bitmap openIcon = Bitmap.getBitmapResource("folder-open.png");
private final Bitmap closedIcon = Bitmap.getBitmapResource("folder-closed.png");
private final Bitmap movieIcon = Bitmap.getBitmapResource("movie.png");
private final Bitmap songIcon = Bitmap.getBitmapResource("song.png");
private final Bitmap playIcon = Bitmap.getBitmapResource("play.png");

public TreeFieldDemoScreen()
{
setTitle("Tree Field Demo");

TreeCallback myCallback = new TreeCallback();
TreeField myTree = new TreeField(myCallback, Field.FOCUSABLE) {
protected boolean navigationClick(int status, int time) {
// We'll only override unvarnished navigation click behavior
if ((status & KeypadListener.STATUS_ALT) == 0 &&
(status & KeypadListener.STATUS_SHIFT) == 0)
{
final int node = getCurrentNode();
if (getFirstChild(node) == -1) {
// Click is on a leaf node. Do some default action or else fall through.

// Note: this will also detect empty folders, which might or
// might not be something your app has to handle
Dialog.alert("clicked " + getCookie(node));
// TODO: open player screen, etc.
return true;
}
}
return super.navigationClick(status, time);
}
};

myTree.setDefaultExpanded(false);
myTree.setRowHeight(openIcon.getHeight());

String nodeOne = new String("Video"); // folder
String nodeTwo = new String("Music"); // folder
String nodeThree = new String("Images"); // folder
String nodeFour = new String("song.mp3");
String nodeFive = new String("movie.m4v");

int node1 = myTree.addChildNode(0, nodeOne);
int node2 = myTree.addChildNode(0, nodeTwo);
int node3 = myTree.addChildNode(0, nodeThree);
int node4 = myTree.addChildNode(node2, nodeFour);
int node5 = myTree.addChildNode(node1, nodeFive);

add(myTree);
}


private class TreeCallback implements TreeFieldCallback
{
public void drawTreeItem(TreeField _tree, Graphics g, int node, int y, int width, int indent)
{
final int PAD = 8;
String text = (String)_tree.getCookie(node);
Bitmap icon = closedIcon;
if (text.endsWith(".mp3")) {
icon = songIcon;
} else if (text.endsWith(".m4v")) {
icon = movieIcon;
} else if (_tree.getExpanded(node)) {
icon = openIcon;
}
g.drawBitmap(indent, y, icon.getWidth(), icon.getHeight(), icon, 0, 0);
// This assumes filenames all contain '.' character!
if (text.indexOf(".") > 0) {
// Leaf node, so this is a playable item (movie or song)
g.drawBitmap(_tree.getWidth() - playIcon.getWidth() - PAD, y + PAD,
playIcon.getWidth(), playIcon.getHeight(), playIcon, 0, 0);
}
int fontHeight = getFont().getHeight();
g.drawText(text, indent + icon.getWidth() + PAD, y + (_tree.getRowHeight() - fontHeight)/2);
}
}
}
我的导航点击处理程序被编码为接受对整个电影或歌曲行的点击,而不仅仅是“播放”按钮本身。我认为这在触摸设备上更容易,因为用户的手指不必击中一个小的触摸目标。不过,如果您愿意,可以更改此设置。
结果
enter image description here
注:我没有费心为图像文件连接一个图标......你现在应该能够做到这一点。

关于blackberry - 具有不同图像和可点击事件的父子节点 - Treeview Blackberry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18485618/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com