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
Contributor
Consilium
Posts: 13
Registered: ‎07-12-2010
My Device: Any
Accepted Solution

setSelectedIndex always focuses on the bottom of the screen

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

 



2549i5F42F570D9896842

What I need it to do is position the list word focus so that is appears in the center of the screen as below

 

2548iF56807B326801CA2

Any advice is appreciated.

 

Thanks you.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: setSelectedIndex always focuses on the bottom of the screen

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

Contributor
Consilium
Posts: 13
Registered: ‎07-12-2010
My Device: Any

Re: setSelectedIndex always focuses on the bottom of the screen

Lol,

 

It works .......hows that for thinking outside the box.

 

Many thanks Peter

 

:smileyhappy:

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: setSelectedIndex always focuses on the bottom of the screen

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!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Consilium
Posts: 13
Registered: ‎07-12-2010
My Device: Any

Re: setSelectedIndex always focuses on the bottom of the screen

K thanks let me try play around with the setVerticalScroll()

 

 

Regular Contributor
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520

Re: setSelectedIndex always focuses on the bottom of the screen

hiii

 

setVerticalScroll() work perfactly 

 

thanks for that...!