Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
click-ma
Posts: 90
Registered: ‎06-15-2009
My Device: Bold 9700

Re: How to Display the content in two lines for ObjectListField

Call setRowHeight method in your constructor.
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to Display the content in two lines for ObjectListField

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)

 



"Listen carefully, I shall say this only once"
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to Display the content in two lines for ObjectListField

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)


 

 

Developer
click-ma
Posts: 90
Registered: ‎06-15-2009
My Device: Bold 9700

Re: How to Display the content in two lines for ObjectListField

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

 

Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to Display the content in two lines for ObjectListField

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.



"Listen carefully, I shall say this only once"
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to Display the content in two lines for ObjectListField

 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??

 

 

 

 

Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to Display the content in two lines for ObjectListField

finally got it working. hopefully no issues should further occur. :smileyhappy:

All i did with the constructor was:

 

 

ArticlesListField() { super(); int rowHeight=30; setRowHeight(rowHeight); }