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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
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..

Developer
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
Developer
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);
    	}
    }
};

 

Highlighted
Developer
Posts: 19,636
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().

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
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
Contributor
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..:-)