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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
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

Please use plain text.
Developer
pradeep_ch
Posts: 540
Registered: ‎12-23-2010
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.

Please use plain text.