07-16-2010 11:47 AM
Hi,
I have the following code.
public final class WordListField extends ListField implements ListFieldCallback {
private Vector _words;
public WordListField(Vector _words, int offset) {
super();
this._words = _words;
setCallback(this);
setSize(_words.size());
}
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
String word = (String) _words.elementAt(index);
int x = 0;
g.drawText(word, x, y, 0, w);
}
public Object get(ListField list, int index) {
return _words.elementAt(index);
}
/**
public int getPreferredWidth(ListField list) {
return Display.getWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return 0;
}
}
public void highlightSelection(String word)
{
WordListField myListView;
Vector wordList= processor.getWordList();
myListView= new WordListField(wordList, 9);
myListView.setSelectedIndex(wordList.indexOf(word) );
}
setSelectedIndex(wordList.indexOf(word)) highlights and selects the correct word
The problem is the display shows the selected word right at the bottom of the screen.
See below
What I need it to do is position the list word focus so that is appears in the center of the screen as below
Any advice is appreciated.
Thanks you.
Solved! Go to Solution.
07-16-2010 01:22 PM
Here is a pretty terrible suggestion.....
My impression is that setSelectedIndex will cause the ListField to Scroll until the row requested is included on the Screen. So how about doing two. Do the first one x past what you want, where x is 1/2 the number of rows on the screen, then do one for the row you really want/ To make sure that the second is processed after the first has really scrolled, package the second one in a
UiApplication.getUiApplication().invokeLater(....)
just a thought.....
07-16-2010 03:18 PM
Lol,
It works .......hows that for thinking outside the box.
Many thanks Peter
![]()
07-16-2010 03:26 PM
For finer control, you may use setVerticalScroll() of the parent Manager of your ListField. If your selected row is still visible with the selected scrolling position the system will not auto-scroll you anywhere else.
And don't forget to give kudos to Peter and mark his reply as a solution. People who search for something similar in the future will see a solved thread and click "Go to solution" to see how it was done. A very useful feature of these forums - utilize it!
07-18-2010 10:35 AM
K thanks let me try play around with the setVerticalScroll()
05-01-2012 10:00 AM
hiii
setVerticalScroll() work perfactly
thanks for that...!