BlackBerry에서 이미지와 텍스트를 한 줄로 나열 할 수있는 ListField를 사용자 정의하고 싶습니다.BlackBerry에서 ListField를 사용자 정의하는 방법은 무엇입니까?
어떻게 수행하나요?
BlackBerry에서 이미지와 텍스트를 한 줄로 나열 할 수있는 ListField를 사용자 정의하고 싶습니다.BlackBerry에서 ListField를 사용자 정의하는 방법은 무엇입니까?
어떻게 수행하나요?
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에서
참조 코드 :
수행하려는 작업에 대해 자세히 알지 못하면서 BlackBerry 개발 환경과 함께 제공되는 몇 가지 샘플 앱을 살펴 보는 것이 좋습니다. 애플 리케이션의 몇 가지 예 PhoneApiDemo.java Contacts.java 로하고 ListField
및 ListFieldCallback
된 구현에 있습니다.
을은 BlackBerry 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."});
@Downvoter : 왜 downvote 댓글 신경? –
나는 downvote를주지는 않지만, 'RichList'와 관련된 질문에 대한 답변이'ListField'의 사용자 정의 가능한 구현이 아니기 때문에 생각합니다. – CAMOBAP
I 레이블 이 답변을 정말 좋아해서 drawListRow에서 모든 종류의 gobbledygook을 수행하지 않고 실제로는 자신 만의 그리기 문제를 처리 할 적절한 필드를 목록 필드에 추가 할 수 있습니다. – Irwin
+1 예, 이것은 좋은 속임수입니다. 그러나 목록이 길면 너무 많은 객체가 생성되어 자연스러운 목적으로 사용되지 않습니다. 이것이 API가 ListField를 제공하여 긴 목록에 리소스를 저장하는 이유입니다. 나는'ListFieldCallback.drawListRow()'를 올바르게 구현하는 것을 선호한다. –
공유에 대한 정말 좋은 예제 큰 감사 :) – Grant