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
BB_AppDeveloper
Posts: 16
Registered: ‎03-22-2013
My Device: 8520,9900,9930,9330,9790,9780
My Carrier: BlackBerry
Accepted Solution

Move focus from listfiled to particular label (horizontal scroll issue)

Hello,

 

In my app I have certain labels(which are focusable) at the top of the screen which I have put in the horizontal field manager(hfm_lbl) with horizontal scroll.

After hfm_lbl , I have one listfiled.

Now when I scroll up the listfiled (i.e.from bottom to top), the focus moves to top but sets at the last menu of the hfm_lbl.

I want the focus to be set on perticular label.

 

Any help is appriciated..

Thanks..

Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Move focus from listfiled to particular label (horizontal scroll issue)

use draw focus method to implement this
Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Move focus from listfiled to particular label (horizontal scroll issue)

use like this:

customEditField = new EditField("","",15, EditField.FOCUSABLE)
{
    protected void drawFocus(Graphics graphics, boolean on) 
    {
    	if(on)
        {
    		super.drawFocus(graphics, on);
    	}
    }
};

 

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: Move focus from ListField to particular label (horizontal scroll issue)

[ Edited ]

drawFocus will not help with this. 

 

The problem is that a HFM, when focus enters it from below, will automatically set the focus on the last item in its list.  So you have to override this processing. 

 

There are actually two options depending on whether you want to override the onFocus method, or use a FocusChangeListener. I know some people have had problems with overriding onFocus(), so recommend the listener. But I never have, so following you will find a sample of the code I use in this circumstance.

 

The trick is that the processing in the HFM must remember the lastFocusField (one of your labels) when focus is moved off it.  This challenge I will leave with you.  Again there are a variety of options and no best one.  So whatever you think up will probably work fine.  One option is to define the HFM as a FocusChangeListener for all the Fields that are added to it, and then remember the last one which gained focus - then the processing is self contained in the HFM. 

 

The following codes assumes lastFocusField is a Field in the HFM, the one the user had focus on before they moved t the ListField.  This method overrides onFocus() in the HFM.

       

        protected void onFocus(int direction) {
                super.onFocus(direction);
                if ( direction != 0 && lastFocusField != null ) {
                        UiApplication.getUiApplication().invokeLater(new Runnable() {
                                public void run() {
                                        lastFocusField.setFocus();
                                }
                        });
                }
        }

 

Edit: I think Simon and I were responding at the same time.  Just to say,in my experience in this specific circumstance, you might be able to do it with moveFocus(), or navigationMovement(), but not as easily as onFocus().

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Move focus from listfiled to particular label (horizontal scroll issue)

No, drawFocus will not help here.

The focus moves in the way fields are added to the screen. If you want to change this behavior you have several options. The most control is offered by overwriting moveFocus, but you can also utilize onFocus or onUnFocus of certain fields, or even navigationMovement. onFocus gives you the direction, so in your usecase you could overwrite it on the last field of your hfm, check for direction < 0 and call setFocus on the first field.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
BB_AppDeveloper
Posts: 16
Registered: ‎03-22-2013
My Device: 8520,9900,9930,9330,9790,9780
My Carrier: BlackBerry

Re: Move focus from ListField to particular label (horizontal scroll issue)

Thanks peter,

 

It worked like a charm for me.

You are simply great..

Thanks a ton..:-)

Please use plain text.