Troubleshooting guide

33
1: Creating UIs
Create custom lists
Task Steps
Let users BlackBerry® device select
multiple items in a list.
> Declare lists as MULTI_SELECT.
Create a callback object. >Implement the ListFieldCallback interface.
private class ListCallback implements ListFieldCallback {
// The listElements vector contain the entries in the list.
private Vector listElements = new Vector();
...
}
Let the field repaint a row. >Implement drawListRow(), invoking drawText() using parameters that specify the row
to paint.
public void drawListRow(ListField list, Graphics g, int index, int
y, int w) {
String text = (String)listElements.elementAt(index);
g.drawText(text, 0, y, 0, w);
}
Let the field retrieve an entry from the list. >Implement get().
public Object get(ListField list, int index) {
return listElements.elementAt(index);
}
Return a preferred width for the list. In the implementation of getPreferredWidth(),return a preferred width for the list.
public int getPreferredWidth(ListField list) {
return Graphics.getScreenWidth();
}
Assign the callback and add entries to the
list.
1. Create the ListField and ListCallback objects for the list.
ListField myList = new ListField();
ListCallback myCallback = new ListCallback();
2. Invoke setCallback() to associate the ListFieldCallback with the ListField.
This association lets the callback add items to the list.
myList.setCallback(myCallback);
3. To add entries to the list, create the entries, specify an index at which to insert each entry on
the
ListField object, and then insert each ListField object into the
ListFieldCallback.
String fieldOne = new String("Field one label");
String fieldTwo = new String("Field two label");
String fieldThree = new String("Field three label");
myList.insert(0);
myList.insert(1);
myList.insert(2);
myCallback.insert(fieldOne, 0);
myCallback.insert(fieldTwo, 1);
myCallback.insert(fieldThree, 2);
mainScreen.add(myList);