Troubleshooting guide

17
1: Creating UIs
Creating custom UI components
To create custom fields, content menus, layout managers, and lists, use the BlackBerry® APIs.
Create a field that lets a BlackBerry
device user select a range of items in
the list.
1. Create the items that you want to display in a ListField.
String fieldOne = new String("Mark Guo");
String fieldTwo = new String("Amy Krul");
2. Create an instance of a ListField.
ListField myList = new ListField();
3. Create an instance of a ListCallback.
ListCallback myCallback = new ListCallback();
4. Set the call back of the ListField to be the ListCallback.
myList.setCallback(myCallback);
5. Use the ListCallBack object to add items to the ListField.
myCallback.add(myList, fieldOne);
myCallback.add(myList, fieldTwo);
6. Add the ListField to the MainScreen.
mainScreen.add(myList);
Create a field that displays a folder or
tree relationship between items such as
documents or message folders.
A TreeField contains parent and child nodes.
1. To draw a TreeField, implement the TreeFieldCallback interface.
2. Specify whether a folder is collapsible by invoking setExpanded() on the TreeField object.
String fieldOne = new String("Main folder");
...
TreeCallback myCallback = new TreeCallback();
TreeField myTree = new TreeField(myCallback, Field.FOCUSABLE);
int node1 = myTree.addChildNode(0, fieldOne);
int node2 = myTree.addChildNode(0, fieldTwo);
int node3 = myTree.addChildNode(node2, fieldThree);
int node4 = myTree.addChildNode(node3, fieldFour);
...
int node10 = myTree.addChildNode(node1, fieldTen);
myTree.setExpanded(node4, false);
...
mainScreen.add(myTree);
Your implementation of TreeFieldCallback should add fields to the tree. See “Create custom
lists” on page 33 for more information about creating callbacks.
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);
g.drawText(text, indent, y);
}
}
Task Steps