07-28-2009 05:34 AM
07-28-2009 06:07 AM
Sure,
Add these lines:
int rowht = listField.getFont().getHeight();
listField.setRowHeight((2 * (rowht))-8);
exactly after you instantiate the list field (right after the: listField = new ListField(); command)
(and remove those same superfluous lines from the drawListRow() method, becuse they are not needed any more)
07-28-2009 07:12 AM
as you will have seen my ArticlesListField extends ObjectListField, so how do i go about doing wot u suggested as
int rowht = listField.getFont().getHeight();
returns an error because of
public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width)
07-28-2009 08:00 AM
Try something like this
private class MyNiceListField extends ObjectListField { private int fontHeight = this.getFont().getHeight(); private static final int UPPER_MARGIN = 1; private static final int INTERLINE = 1; private static final int NUM_OF_ROWS = 2; private static final int TEXT_MARGIN = 2; private int rowHeight = NUM_OF_ROWS*fontHeight + UPPER_MARGIN + INTERLINE; MyNiceListField() { super(); setRowHeight(rowHeight); } // Take care of drawing the item. public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) { int ypos = y + UPPER_MARGIN; int xpos = TEXT_MARGIN; String str1 = "line 1"; String str2 = "line 2"; /* First line: */ graphics.drawText(str1, xpos, ypos, DrawStyle.ELLIPSIS, width); /* Second line: */ ypos += fontHeight + INTERLINE; graphics.drawText(str2, xpos, ypos, DrawStyle.ELLIPSIS, width); } } /* MyNiceListField */
HTH
07-28-2009 09:04 AM
sorry. didn't notice the extended part (silly me).
click-ma showed the appraach in an extended listField class.
The point is not to set the row height every time the row get's drawn because that change will be applied to the next row (thus skipping the first one).
By putting the setRowHeight(int aHeight) in the constructor you are sure that the call is done once per instatination and before any drawing being done.
So every row will have this aHeight set.
07-29-2009 01:11 AM
public void setRowHeight(int rowHeight) { rowHeight = 30; };
i wrote the setRowHeight method as above and called the method as below
private class ArticlesListField extends ObjectListField { private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rowBckgrd_grey.png"); private Bitmap focusBitmap = Bitmap.getBitmapResource("rowBckgrd_blue.png"); private Bitmap icon = Bitmap.getBitmapResource("icon_coupon.png"); ArticlesListField() { super(); setRowHeight(rowHeight); }
But i get an error as follows:
cannot find symbol symbol : variable rowHeight location: class RestaurantScreen.ArticlesListField setRowHeight(rowHeight); ^
Wots the issue??
07-29-2009 02:06 AM
finally got it working. hopefully no issues should further occur. ![]()
All i did with the constructor was:
ArticlesListField() { super(); int rowHeight=30; setRowHeight(rowHeight); }