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);
}
}
}
黑莓开发:怎么样制作一个TreeField
文章评分1次,平均分5.0:★★★★★