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
New Developer
jimmy6
Posts: 40
Registered: ‎05-12-2009
My Device: Not Specified

field.updateLayout cause scroll to top

When i call field.updateLayout the page will scroll to top but i just want it remain same position. How to do that?
Please use plain text.
Developer
mantaker
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: field.updateLayout cause scroll to top

This happens as expected, when you update a layout it is common for the screen to go to the start.. To work around this to get your expected results, find which field has the focus currently(before calling update layout), and then setFocus to that field after the update layout..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Please use plain text.
New Contributor
optimus_prime
Posts: 6
Registered: ‎05-08-2012
My Device: BB 9800
My Carrier: At&t

Re: field.updateLayout cause scroll to top

hi,

 

i am trying to scroll verticalfield to a specific point(height) and make the field show on top of the page by calling setVerticalScroll() witin the layout method of the field:

 

protected void layout(int width, int height) {
_setExtent(getPreferredWidth(), getPreferredHeight());
// To try to scroll the list so that the focus field is shown on top of the page
if (this.getIndex() == this.getManager().getField(this.getManager().getFieldCount()-1).getIndex()) {
this.getManager().setVerticalScroll(this.getManager().getFieldWithFocus().getTop());

}
}

 

but the field doesnt scroll to the position. it however scrolls to the visible rect of the screen since the field's focus is true.

 

Can you please tell why the is not working... 

 

Thanks

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: field.updateLayout cause scroll to top

One of the absolute first things to do in such cases is to wrap your setVerticalScroll in invokeLater. Calculate the position into a final int and invokeLater the setVerticalScroll call.

 

The reason is simple - since you don't know in what order the BB framework invokes fields' methods, you want to make sure your setVerticalScroll runs after the UI engine has completely finished the layout update.

 

See if that helps.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
New Contributor
optimus_prime
Posts: 6
Registered: ‎05-08-2012
My Device: BB 9800
My Carrier: At&t

Re: field.updateLayout cause scroll to top

@arkadyz  : 

thanks a lot for you reply. will try this out.


Please use plain text.