Here my custom listfield
public Custom_ListField(String title[], String date[], String category[]) {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setCallback(this);
Background background = BackgroundFactory.createBitmapBackground(bg);
setBackground(background);
rows = new Vector();
for (int x = 0; x < title.length; x++) {
TableRowManager row = new TableRowManager();
titlelabel = new LabelField(title[x], DrawStyle.ELLIPSIS
| LabelField.USE_ALL_WIDTH | DrawStyle.LEFT);
titlelabel.setFont(Font.getDefault().derive(Font.BOLD, 25));
row.add(titlelabel);
datelabel = new LabelField(date[x], DrawStyle.ELLIPSIS
| LabelField.USE_ALL_WIDTH | DrawStyle.LEFT);
datelabel.setFont(Font.getDefault().derive(Font.BOLD, 20));
row.add(datelabel);
categorylabel = new LabelField(category[x], DrawStyle.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
categorylabel.setFont(Font.getDefault().derive(Font.BOLD, 20));
row.add(categorylabel);
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
list = (Custom_ListField) 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);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.popContext();
}
protected void sublayout(int width, int height) {
Field field = getField(0);
layoutChild(field, getPreferredWidth() - 16, 25);
setPositionChild(field, 5, 5);
field = getField(1);
layoutChild(field, 100, 20);
setPositionChild(field, 5, 35);
field = getField(2);
layoutChild(field, 100, 20);
setPositionChild(field, 110, 35);
setExtent(getPreferredWidth(), getPreferredHeight());
}
As you can see, the first and second row look like no problem, but the problem goes to third row onward. The margin of the text getting larger and larger. To see clearly, my background image does have a clear separator line.
What is the problem?
Actually this problem is because of sublayout method of your TableRowManager class.
setPositionChild(getField(0), 10, 5);
layoutChild(getField(0), getField(0).getPreferredWidth(),
getField(0).getPreferredHeight());
Here the setPosition method(To position that particular field:::: For Example,set the left and the top margin) having 3 argument. 1st one is the field which is going to be positioned. 2nd one is the left side margin for that field. 3rd one is the top margin for that field.
Similarly for the layout method(To layout that particular field:::: For Example,set the width and height of that field) also having 3 argument. 1st one is the field which is going to layout. 2nd one is to get the preferred width of that field. 3rd one is to get the preferred height of that field.
Understand the purpose of each and every argument of both the method and then use that properly. I hope this would helps u.
Change your sublayout method and let me know about your result.