Blackberry - 如何使用复选框在 ListField 中进行文本换行?
我正在创建一个带有复选框的 ListField 如何 - 创建带有复选框的 ListField
但我不知道如何在该 ListField 中将文本换行。
我提到了线程 列表字段项中文本的文本换行
这里写为
如果您显示的只是文本,那么我会采用 rab 建议的方法。
我仅在 ListField 中显示文本,如果它不适合设备屏幕,我想将其换行。
但我没有得到“rab 建议的方法”,其中如何计算?
String[]linesToDraw = 根据行宽计算行数
我被困在这个问题上,所以关于这个问题的任何细节?
按照你的逻辑,我知道
* 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
我正在这样做
if(getFont().getAdvance(lineStr+" "+words[i]) < Display.getWidth())
{
lineStr += words[i];
}
&我将 lineStr 存储在 VectorlinesToDraw 中,与我用于存储下一行文本的 lineStr 相同。
&最后我正在做绘图,
for (int i = 0; i < linesToDraw.size(); i++)
{
String textToDraw = (String)linesToDraw.elementAt(i);
graphics.drawText(textToDraw, 0, y, 0, w);
y += fontHeight;
}
但如何计算没有。一行的行&行高?
这样,有了这个行高,我就可以编写 setRowHeight(rowHeight) ,因为不同行的行高不同。
我得到了没有。根据行宽和行数正确排列行将其存储在 Vector & 中我
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;
}
现在正在绘制线条,但在前一条上,默认情况下 listField.setRowHeight() 仅占用一行。如果有 r 2 行,那么我在 drawListRow() 中写入 setRowHeight(getFont().getHeight()*2) 但随后它会进入循环
如果我在创建 ListField 时写入 setRowHeight() 那么它会正常显示,但对于所有行,行高相同已设置。
我得到要在运行时绘制的字符串&行高对于不同的行应该是可变的,那么我如何使用什么参数来 setRowHeight() ?用哪种方法?
I m creating 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 items
Here 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为“根据行宽计算行数”意味着:
最后你会得到:
I think "calculate the number of lines depending on the row width" means:
in the end you will get: