首页 » 黑莓开发 » 黑莓开发:怎么样制作一个TreeField

黑莓开发:怎么样制作一个TreeField

3753 0

package newpackage;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.Dialog;
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;
/**
*
* @author Tiandi Zhang
*/
public class Demo extends UiApplication {
public static void main(String[] args){
Demo theApp = new Demo();
theApp.enterEventDispatcher();
}
public Demo(){
pushScreen(new mainscreen());
}
}
class mainscreen extends MainScreen{
public mainscreen() {
super();
LabelField title = new LabelField("Tree Demo",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH);
setTitle(title);
treeCallback tc = new treeCallback();
TreeField b1 = new TreeField(tc,Field.FOCUSABLE){
protected boolean navigationClick(int status, int time){
if(this.getCookie(this.getCurrentNode())== "male")
Dialog.alert("male");
else if(this.getCookie(this.getCurrentNode())== "female")
Dialog.alert("female");
else if(this.getCookie(this.getCurrentNode())== "Zhang")
Dialog.alert("Zhang");
else if(this.getCookie(this.getCurrentNode())== "Jacky Zhang")
Dialog.alert("Jacky Zhang");
else if(this.getCookie(this.getCurrentNode())== "Peter Zhang")
Dialog.alert("Peter Zhang");
return true;
}
};
int n1 = b1.addChildNode(0, "male");
int n2 = b1.addChildNode(0, "female");
int n3 = b1.addChildNode(n1, "Zhang");
int n4 = b1.addChildNode(n3, "Jacky Zhang");
int n5 = b1.addChildNode(n3, "Peter Zhang");
add(b1);
}
}
class treeCallback implements TreeFieldCallback {
public void drawTreeItem(TreeField treeField, Graphics graphics, int node, int y, int width, int indent) {
Object obj = treeField.getCookie(node);
if (obj instanceof String)
{
String text = (String)obj;
graphics.drawText(text, indent*10/7, y);
}
}
}

文章评分1次,平均分5.0

本文原始地址:https://www.tiandiyoyo.com/2010/02/%e9%bb%91%e8%8e%93%e5%bc%80%e5%8f%91%ef%bc%9a%e6%80%8e%e4%b9%88%e6%a0%b7%e5%88%b6%e4%bd%9c%e4%b8%80%e4%b8%aatreefield/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

    没有相关的文章

评论前先开启评论开关: