I am working on an application that requires text larger than the viewable screen size in both a TreeField and a ListField. As you know, the TreeField and ListField callbacks support only graphics.drawText() methods, so I cannot add an instance of a Field per row.
Does anyone have a method of Scrolling horizontally past the viewab开发者_运维百科le text size?
Is there maybe a scrollable panel that would work? I know of the NullField(Field.Focusable) trick but this won't work on the list field.
Lastly, I am aware that the type of screen makes a different as FullScreen and MainScreen use VerticalFieldMangers. So am using a PopupScreen at the moment for my testing.
Thank you in advance for your time.
Maybe it's better to split text in two lines and set row height 2 x font height (+ margins)?
alt text http://img219.imageshack.us/img219/5802/listh.jpg
class Scr extends MainScreen implements ListFieldCallback {
int DISPLAY_WIDTH = Display.getWidth();
Vector mItems = new Vector();
ListField mListField = new ListField();
public Scr() {
mListField.setCallback(this);
add(mListField);
mItems.addElement("Lorem ipsum dolor sit amet, ");
mItems.addElement("Lorem ipsum dolor sit");
mItems.addElement("Lorem ipsum dolor sit amet, "+
"consectetuer adipiscing elit");
mItems.addElement("Lorem ipsum dolor sit amet, "+
"consectetuer adipiscing elit, sed diam "+
"nonummy nibh euismod");
mItems.addElement("Lorem ipsum dolor sit amet, "+
"consectetuer adipiscing elit");
mItems.addElement("Lorem ipsum dolor sit amet, ");
mListField.setSize(mItems.size());
mListField.setRowHeight(
mListField.getFont().getHeight()*2 + 4);
}
public void drawListRow(ListField field, Graphics g,
int i, int y, int w) {
// Draw the text.
String text = (String) get(field, i);
if(g.getFont().getAdvance(text) > w)
{
int index = 0;
while(g.getFont().getAdvance(text.substring(0, index)) < w)
{
index++;
}
g.drawText(text.substring(0, index), 0, y, 0, w);
g.drawText(text.substring(index, text.length()-1), 0,
y + g.getFont().getHeight()+ 4, DrawStyle.ELLIPSIS, w);
}
else
{
g.drawText(text, 0, y, 0, w);
}
}
public Object get(ListField listField, int index) {
return mItems.elementAt(index);
}
public int getPreferredWidth(ListField listField) {
return DISPLAY_WIDTH;
}
public int indexOfList(ListField listField,
String prefix, int start) {
return 0;
}
}
精彩评论