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: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Set focus on perticular field

I have 5 bitmapfields in horizontalfield manager. When screen is displayed focus is set to first bitmapfield by default. i want to set it to 2nd bitmapfield. how to do it?

HorizontalfieldManager h = new HorizontalFieldManager()

{

protected void sublayout(int maxWidth, int maxHeight) {
Field f = this.getField(2);
f.setFocus();
 super.sublayout(maxWidth, maxHeight);

}

I tried above code. Still focus is set on first field

Highlighted
Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Set focus on perticular field

Hi Jovinz,

 

The better approach to set focus after screen loads into stack is,

 

protected void onUiEngineAttached(boolean attached) {
        if(attached){
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
               Field f =//get your required field

if(f != null)f.setFocus();
            }
        });
        }
    }

 

Thanks.