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
Developer
Posts: 23
Registered: ‎12-21-2009
My Device: 8800
My Carrier: Zain

Re: How to scroll the ListField to the selected index

 


BBDeveloper wrote:

check for indexOfList method too..


 

this method is to search the list, how it could be useful in my case?

 

Developer
Posts: 23
Registered: ‎12-21-2009
My Device: 8800
My Carrier: Zain

Re: How to scroll the ListField to the selected index

 


schepurny wrote:

I'm assuming you have a list model overriding the drawListRow method. If that's the case, I imagine you could put code in there to exclude drawing the rows that you don't want to see. Then just do an invalidate() and that should work.

 

Something like this...

 

 public void drawListRow(ListField list, Graphics g, int index, int y, int w) {

if (index < newStartingIndex) {return;}  //don't draw row

 

...

..

 

 


 

 

maybe this is the right direction if there is no method to do it for me, but it is not easy as it seems to be. When I skip the rows, the list show blank rows instead of the rows I skip, because the y coordinate is sent from the ListField class which managed by the VerticalFieldManager.

 

any suggestions to fix this...

Developer
Posts: 23
Registered: ‎12-21-2009
My Device: 8800
My Carrier: Zain

Re: How to scroll the ListField to the selected index

[ Edited ]

I managed to solve my problem, I was thinking to look on the Manager class to solve my previous problem and I found this beautiful method setVerticalScroll(int posotion), it will move the scroll to a new position.

 

so simply I used this:

 

 

listField.setSelectedIndex( index );
Manager manager = listField.getManager();
manager.setVerticalScroll( index * rowHeight );
listField.invalidate();

 

which first set the focus to the new index, then scroll the list so the row will be the first row to draw.

 

Contributor
Posts: 14
Registered: ‎10-31-2010
My Device: Not Specified

Re: How to scroll the ListField to the selected index

It seems like setSelectedItem(posiotion) does not working.

The cursor located in the first item whenever list updated.

The code:

				listField.setKeyword("");
				listField.v = userVector;				
				listField.updateList();	
//				listField.getResultList();			
				listField.setSelectedIndex(lastPosition);	
				listField.setFocus();
				Manager manager = listField.getManager();
				int height = listField.getRowHeight() * lastPosition;
				manager.setVerticalScroll(height);
				listField.invalidate();

 

Contributor
Posts: 14
Registered: ‎10-31-2010
My Device: Not Specified

Re: How to scroll the ListField to the selected index

It seems like setSelectedItem(posiotion) does not working.

The cursor located in the first item whenever list updated.

The code:

				listField.setKeyword("");
				listField.v = userVector;				
				listField.updateList();	
				listField.getResultList();			
				listField.setSelectedIndex(lastPosition);	
				listField.setFocus();
				Manager manager = listField.getManager();
				int height = listField.getRowHeight() * lastPosition;
				manager.setVerticalScroll(height);
				listField.invalidate();