我试过这个链接How to customize a ListField in BlackBerry? 为每个列表行创建具有三个标签字段的 ListField。但我无法看到列表字段项目。但我可以说添加了列表字段。因为在导航上单击我可以获得列表字段的选定索引。请任何人帮助在哪里我做错了。我尝试过的代码是......
public class InboxWithOutCheckboxeslistfield extends ListField implements ListFieldCallback {
private Vector rows;
private TableRowManager row ;
private LabelField UserName,Message,Timestamp;
/**
* Creates a new MyScreen object
*/
public InboxWithOutCheckboxeslistfield() {
// TODO Auto-generated constructor stub
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setCallback(this);
rows = new Vector();
for (int x = 0; x < 10; x++) {
row = new TableRowManager();
UserName = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.LEFT);
UserName.setText("name");
row.add(UserName);
Message = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Message.setText("hai");
row.add(Message);
Timestamp = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Timestamp.setText("hai");
row.add(Timestamp);
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
// TODO Auto-generated method stub
InboxWithOutCheckboxeslistfield list = (InboxWithOutCheckboxeslistfield) listField;
TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
rowManager.drawRow(graphics, 0, y, width, list.getRowHeight());
}
public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return null;
}
public int getPreferredWidth(ListField listField) {
// TODO Auto-generated method stub
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return 0;
}
private class TableRowManager extends Manager {
protected TableRowManager(){super(0);
// TODO Auto-generated constructor stub}
}
public void drawRow(Graphics graphics, int i, int y, int width,
int rowHeight) {
// TODO Auto-generated method stub
// Arrange the cell fields within this row manager.
layout(width, rowHeight);
// Place this row manager within its enclosing list.
setPosition(i, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
graphics.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(graphics);
graphics.setColor(0x00CACACA);
graphics.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
graphics.popContext();
}
protected void sublayout(int width, int height) {
// TODO Auto-generated method stub
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the list name label field
field = getField(1);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
// set the due time name label field
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(getPreferredWidth(), getPreferredHeight());
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth()
{
return getWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight()
{
return getHeight();
}
}
protected boolean navigationClick(int status, int time) {
int index1 = getSelectedIndex();
System.out.println("The Clikced item is:"+index1);
return true;
}
}
主屏幕类是
public class InboxWithOutCheckboxes extends MainScreen{
private InboxWithOutCheckboxeslistfield inboxWithOutCheckboxeslistfield;
public InboxWithOutCheckboxes(){
super();
inboxWithOutCheckboxeslistfield = new InboxWithOutCheckboxeslistfield();
add(inboxWithOutCheckboxeslistfield);
add(new SeparatorField());
}
}