Blackberry - How to do text wrapping in ListField with Checkboxes?
I m creating开发者_C百科 a ListField with Checkboxes from How To - Create a ListField with check boxes
But I m not getting how to wrap Text in a row in that ListField. I referred the thread Text Wrapping for text in List Field itemsHere its written as
If all you are displaying is text, then I would go with the approach suggested by rab.
I m displaying Text only in ListField which I want to wrap if it doesnt fit within device screen.
But i m not getting "approach suggested by rab" in which How to calculate?String [] linesToDraw = calculate the number of lines depending on the row width
I m stucked at this so any details on this issue ?
With ur logic I got
* split text on words
* create string array and while words array not empty do
o create string lineStr
o while getFont().getAdvance(lineStr+" "+words[i]) < row width move words[i] to lineStr
I m doing it like
if(getFont().getAdvance(lineStr+" "+words[i]) < Display.getWidth())
{
lineStr += words[i];
}
& I m storing lineStr in a Vector linesToDraw as the same lineStr I m using for storing text of next row.
& in the end for drawing I m doing
for (int i = 0; i < linesToDraw.size(); i++)
{
String textToDraw = (String)linesToDraw.elementAt(i);
graphics.drawText(textToDraw, 0, y, 0, w);
y += fontHeight;
}
but how to calculate no. of lines of a row & row height?
so that with this row height I can write setRowHeight(rowHeight) as the row height is different for different rows.
I got the no. of lines properly according to row width & stored it in a Vector & i m doing
int fontHeight = this.getFont().getHeight();
for (int i = 0; i < linesToDraw .size(); i++)
{
textToDraw = (String)linesToDraw.elementAt(i);
graphics.drawText(textToDraw, xpos, ypos, 0 , width);
ypos += fontHeight;
}
now its drawing the lines but over the previous one as by default listField.setRowHeight() is taking only one row. If there r 2 rows then I write setRowHeight(getFont().getHeight()*2) in drawListRow() but then it goes in loop
If I write setRowHeight() while creating ListField then it comes properly but for all rows same row height is set.
I gets the String to draw at Runtime & the row height should be variable for different rows then how can I setRowHeight() with what parameter & in which method ?
I think "calculate the number of lines depending on the row width" means:
- split text on words
- create string array and while words array not empty do
- create string lineStr
- while getFont().getAdvance(lineStr+" "+words[i]) < row width move words[i] to lineStr
in the end you will get:
- String[] lines with lines for row
- Row height = lines.lenght * (getFont().getHeight() + topMargin + bottomMargin)
精彩评论