如何在BlackBerry中自定义ListField?

我想在BlackBerry中自定义ListField,以便能够连续列出图像和文本。


如何做到这一点?


慕工程0101907
浏览 328回答 3
3回答

素胚勾勒不出你

尝试这样的事情:class TaskListField extends ListField implements ListFieldCallback {&nbsp;private Vector rows;&nbsp;private Bitmap p1;&nbsp;private Bitmap p2;&nbsp;private Bitmap p3;&nbsp;public TaskListField() {&nbsp; super(0, ListField.MULTI_SELECT);&nbsp; setRowHeight(80);&nbsp; setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);&nbsp; setCallback(this);&nbsp; p1 = Bitmap.getBitmapResource("1.png");&nbsp; p2 = Bitmap.getBitmapResource("2.png");&nbsp; p3 = Bitmap.getBitmapResource("3.png");&nbsp; rows = new Vector();&nbsp; for (int x = 0; x < 10; x++) {&nbsp; &nbsp;TableRowManager row = new TableRowManager();&nbsp; &nbsp;// SET THE PRIORITY BITMAP FIELD&nbsp; &nbsp;// if high priority, display p1 bitmap&nbsp; &nbsp;if (x % 2 == 0) {&nbsp; &nbsp; row.add(new BitmapField(p1));&nbsp; &nbsp;}&nbsp; &nbsp;// if priority is 2, set p2 bitmap&nbsp; &nbsp;else if (x % 3 == 0) {&nbsp; &nbsp; row.add(new BitmapField(p2));&nbsp; &nbsp;}&nbsp; &nbsp;// if priority is 3, set p3 bitmap&nbsp; &nbsp;else {&nbsp; &nbsp; row.add(new BitmapField(p3));&nbsp; &nbsp;}&nbsp; &nbsp;// SET THE TASK NAME LABELFIELD&nbsp; &nbsp;// if overdue, bold/underline&nbsp; &nbsp;LabelField task = new LabelField("Task #" + String.valueOf(x),&nbsp; &nbsp; &nbsp;DrawStyle.ELLIPSIS);&nbsp; &nbsp;// if due today, bold&nbsp; &nbsp;if (x % 2 == 0) {&nbsp; &nbsp; task.setFont(Font.getDefault().derive(&nbsp; &nbsp; &nbsp; Font.BOLD | Font.UNDERLINED));&nbsp; &nbsp; System.out.println("OVERDUE");&nbsp; &nbsp;} else {&nbsp; &nbsp; task.setFont(Font.getDefault().derive(Font.BOLD));&nbsp; &nbsp; System.out.println("TODAY");&nbsp; &nbsp;}&nbsp; &nbsp;row.add(task);&nbsp; &nbsp;// SET THE LIST NAME&nbsp; &nbsp;row.add(new LabelField("List Name #" + String.valueOf(x),&nbsp; &nbsp; &nbsp;DrawStyle.ELLIPSIS) {&nbsp; &nbsp; protected void paint(Graphics graphics) {&nbsp; &nbsp; &nbsp;graphics.setColor(0x00878787);&nbsp; &nbsp; &nbsp;super.paint(graphics);&nbsp; &nbsp; }&nbsp; &nbsp;});&nbsp; &nbsp;// SET THE DUE DATE/TIME&nbsp; &nbsp;row.add(new LabelField("Due Date #" + String.valueOf(x),&nbsp; &nbsp; &nbsp;DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH&nbsp; &nbsp; &nbsp; &nbsp;| DrawStyle.RIGHT) {&nbsp; &nbsp; protected void paint(Graphics graphics) {&nbsp; &nbsp; &nbsp;graphics.setColor(0x00878787);&nbsp; &nbsp; &nbsp;super.paint(graphics);&nbsp; &nbsp; }&nbsp; &nbsp;});&nbsp; &nbsp;rows.addElement(row);&nbsp; }&nbsp; setSize(rows.size());&nbsp;}&nbsp;// ListFieldCallback Implementation&nbsp;public void drawListRow(ListField listField, Graphics g, int index, int y,&nbsp; &nbsp;int width) {&nbsp; TaskListField list = (TaskListField) listField;&nbsp; TableRowManager rowManager = (TableRowManager) list.rows&nbsp; &nbsp; .elementAt(index);&nbsp; rowManager.drawRow(g, 0, y, width, list.getRowHeight());&nbsp;}&nbsp;private class TableRowManager extends Manager {&nbsp; public TableRowManager() {&nbsp; &nbsp;super(0);&nbsp; }&nbsp; // Causes the fields within this row manager to be layed out then&nbsp; // painted.&nbsp; public void drawRow(Graphics g, int x, int y, int width, int height) {&nbsp; &nbsp;// Arrange the cell fields within this row manager.&nbsp; &nbsp;layout(width, height);&nbsp; &nbsp;// Place this row manager within its enclosing list.&nbsp; &nbsp;setPosition(x, y);&nbsp; &nbsp;// Apply a translating/clipping transformation to the graphics&nbsp; &nbsp;// context so that this row paints in the right area.&nbsp; &nbsp;g.pushRegion(getExtent());&nbsp; &nbsp;// Paint this manager's controlled fields.&nbsp; &nbsp;subpaint(g);&nbsp; &nbsp;g.setColor(0x00CACACA);&nbsp; &nbsp;g.drawLine(0, 0, getPreferredWidth(), 0);&nbsp; &nbsp;// Restore the graphics context.&nbsp; &nbsp;g.popContext();&nbsp; }&nbsp; // Arrages this manager's controlled fields from left to right within&nbsp; // the enclosing table's columns.&nbsp; protected void sublayout(int width, int height) {&nbsp; &nbsp;// set the size and position of each field.&nbsp; &nbsp;int fontHeight = Font.getDefault().getHeight();&nbsp; &nbsp;int preferredWidth = getPreferredWidth();&nbsp; &nbsp;// start with the Bitmap Field of the priority icon&nbsp; &nbsp;Field field = getField(0);&nbsp; &nbsp;layoutChild(field, 32, 32);&nbsp; &nbsp;setPositionChild(field, 0, 0);&nbsp; &nbsp;// set the task name label field&nbsp; &nbsp;field = getField(1);&nbsp; &nbsp;layoutChild(field, preferredWidth - 16, fontHeight + 1);&nbsp; &nbsp;setPositionChild(field, 34, 3);&nbsp; &nbsp;// set the list name label field&nbsp; &nbsp;field = getField(2);&nbsp; &nbsp;layoutChild(field, 150, fontHeight + 1);&nbsp; &nbsp;setPositionChild(field, 34, fontHeight + 6);&nbsp; &nbsp;// set the due time name label field&nbsp; &nbsp;field = getField(3);&nbsp; &nbsp;layoutChild(field, 150, fontHeight + 1);&nbsp; &nbsp;setPositionChild(field, preferredWidth - 152, fontHeight + 6);&nbsp; &nbsp;setExtent(preferredWidth, getPreferredHeight());&nbsp; }&nbsp; // The preferred width of a row is defined by the list renderer.&nbsp; public int getPreferredWidth() {&nbsp; &nbsp;return Graphics.getScreenWidth();&nbsp; }&nbsp; // The preferred height of a row is the "row height" as defined in the&nbsp; // enclosing list.&nbsp; public int getPreferredHeight() {&nbsp; &nbsp;return getRowHeight();&nbsp; }&nbsp;}&nbsp;public Object get(ListField listField, int index) {&nbsp; return null;&nbsp;}&nbsp;public int getPreferredWidth(ListField listField) {&nbsp; return 0;&nbsp;}&nbsp;public int indexOfList(ListField listField, String prefix, int start) {&nbsp; return 0;&nbsp;}}

喵喵时光机

从BlackBerry Java SDK 6.0开始,您可以使用RichList:使用丰富列表显示项目列表,这些项目的左侧包含一个可选图像,该图像旁边的标签列表以及该图像和标签下方的可选描述RichList list = new RichList(mainManager, true, 2, 1);list.add(new Object[] {bitmap1, "Device 1",&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"BlackBerry Smartphone 9500",&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Description of Device 1."});list.add(new Object[] {bitmap2, "Device 2",&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"BlackBerry Smartphome 9000",&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Description of Device 2."});
打开App,查看更多内容
随时随地看视频慕课网APP