15
A
回答
52
screenshot http://img10.imageshack.us/img10/1410/listfield.jpg
尝试是这样的:
class TaskListField extends ListField implements ListFieldCallback {
private Vector rows;
private Bitmap p1;
private Bitmap p2;
private Bitmap p3;
public TaskListField() {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
setCallback(this);
p1 = Bitmap.getBitmapResource("1.png");
p2 = Bitmap.getBitmapResource("2.png");
p3 = Bitmap.getBitmapResource("3.png");
rows = new Vector();
for (int x = 0; x < 10; x++) {
TableRowManager row = new TableRowManager();
// SET THE PRIORITY BITMAP FIELD
// if high priority, display p1 bitmap
if (x % 2 == 0) {
row.add(new BitmapField(p1));
}
// if priority is 2, set p2 bitmap
else if (x % 3 == 0) {
row.add(new BitmapField(p2));
}
// if priority is 3, set p3 bitmap
else {
row.add(new BitmapField(p3));
}
// SET THE TASK NAME LABELFIELD
// if overdue, bold/underline
LabelField task = new LabelField("Task #" + String.valueOf(x),
DrawStyle.ELLIPSIS);
// if due today, bold
if (x % 2 == 0) {
task.setFont(Font.getDefault().derive(
Font.BOLD | Font.UNDERLINED));
System.out.println("OVERDUE");
} else {
task.setFont(Font.getDefault().derive(Font.BOLD));
System.out.println("TODAY");
}
row.add(task);
// SET THE LIST NAME
row.add(new LabelField("List Name #" + String.valueOf(x),
DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
// SET THE DUE DATE/TIME
row.add(new LabelField("Due Date #" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
rows.addElement(row);
}
setSize(rows.size());
}
// ListFieldCallback Implementation
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
TaskListField list = (TaskListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows
.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
// Causes the fields within this row manager to be layed out then
// painted.
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
// Place this row manager within its enclosing list.
setPosition(x, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
g.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
// Arrages this manager's controlled fields from left to right within
// the enclosing table's columns.
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
// start with the Bitmap Field of the priority icon
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
// set the task name label field
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the list name label field
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
// set the due time name label field
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(preferredWidth, getPreferredHeight());
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
从
rtm4bb - A BlackBerry Client for Remember the Milk
见代码:
4
不知道你想要做什么的更多细节,我建议看一看BlackBerry开发环境附带的一些示例应用程序。几个应用程序,如Contacts.java和PhoneApiDemo.java有一个ListField
和ListFieldCallback
实现。
0
与黑莓的Java SDK 6.0开始,你可以使用一个RichList
:
使用富豪榜显示包含在左侧,图像旁边的标签和图像下方的可选 描述列表的可选 图像的项目清单和标签
RichList list = new RichList(mainManager, true, 2, 1);
list.add(new Object[] {bitmap1, "Device 1",
"BlackBerry Smartphone 9500",
"Description of Device 1."});
list.add(new Object[] {bitmap2, "Device 2",
"BlackBerry Smartphome 9000",
"Description of Device 2."});
+0
@Downvoter:照顾评论为什么downvote? – 2014-01-14 04:55:48
+0
我不会对你产生不满,但我认为因为你的回答与问题无关,'RichList'不是'ListField'的可定制实现。 – CAMOBAP 2014-05-27 14:55:38
相关问题
- 1. 如何自定义listfield项目?
- 2. BlackBerry - 如何将clickEvent(setChangeListener)添加到BlackBerry中的ListField?
- 3. 在BlackBerry ListField中绘制边框
- 4. BlackBerry动态更新ListField
- 5. 在BlackBerry中创建自定义布局
- 6. BlackBerry ListField - 如何打开选定的列表项
- 7. BlackBerry - 自定义布局
- 8. BlackBerry自定义HorizontalFieldManager
- 9. 如何在j2me/blackberry中添加自定义事件?
- 10. Blackberry-如何在每行上方制作ListField标题
- 11. 如何在BlackBerry上的Bitmap/BitmapField上自定义绘图?
- 12. 将标签添加到BlackBerry ListField
- 13. Blackberry 6:ListField - 限制显示行数?
- 14. Blackberry - ListField与来自文件系统的图像
- 15. 带有来自URL(XML数据)的图像的Blackberry-ListField
- 16. Blackberry - 如何在带有复选框的ListField中进行文本换行?
- 17. 在BlackBerry中创建带有图像的ListField
- 18. BlackBerry的自定义标签字段
- 19. BlackBerry - 自定义菜单工具栏
- 20. BlackBerry - 处理自定义协议
- 21. 如何更改焦点上的自定义buttonfield位图? (Blackberry)
- 22. 如何编写phonegap + blackberry 10的自定义插件?
- 23. 在BlackBerry OS中自定义日期分析
- 24. 如何处理排在ListField
- 25. django为“ListField”自定义窗口小部件并显示列表
- 26. BlackBerry上的ListField行中的文字环绕
- 27. 如何在自定义类中创建自定义IBActions?
- 28. 如何在自定义BaseAdapter中使用自定义字体
- 29. 如何在自定义中插入和添加自定义行?
- 30. 在自定义小部件中自定义onClickListner - 如何?
我真的很喜欢这个答案,它不再需要在drawListRow中做所有类型的gobbledygook,而是实际上允许你在列表字段中添加适当的字段来处理他们自己的绘图问题。 – Irwin 2011-06-25 21:10:07
+1是的,这是一个不错的窍门。但是,如果列表很长,则会创建太多的对象,但不会用于其自然目的。这就是API提供'ListField'的原因 - 将资源保存在长列表中。我宁愿恰当地实现'ListFieldCallback.drawListRow()'。 – 2011-09-13 11:53:05
真的很好的例子非常感谢分享:) – Grant 2013-05-11 08:43:26