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
alfonsn
Posts: 34
Registered: ‎08-11-2011
My Carrier: Axis
Accepted Solution

Handling Focus When Entering A Manager

[ Edited ]

Hi.

 

Say I have a manager with 3 fields added to it. How do I make it so that every time focus enters the manager, the second field within the manager gets the focus?

 

Thanks in advance.

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

Re: Handling Focus When Entering A Manager

you could overwrite moveFocus. or overwrite onFocus on the other fields.
----------------------------------------------------------
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
alfonsn
Posts: 34
Registered: ‎08-11-2011
My Carrier: Axis

Re: Handling Focus When Entering A Manager

[ Edited ]

I don't quite understand how to override the moveFocus method. Could you give me an example?

 

P.S. Do you know whether a manager's onFocus method can be overwritten? And if so, would it be possible for me to just use manager.getField(i) and then setFocus() to it to achieve my goal?

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

Re: Handling Focus When Entering A Manager


alfonsn wrote:

P.S. Do you know whether a manager's onFocus method can be overwritten? And if so, would it be possible for me to just use manager.getField(i) and then setFocus() to it to achieve my goal?


Yes, onFocus can be overwritten, and yes, you nailed it - that's one of the approaches that work.

----------------------------------------------------------
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.
Contributor
alfonsn
Posts: 34
Registered: ‎08-11-2011
My Carrier: Axis

Re: Handling Focus When Entering A Manager

I tried overriding the onFocus method of my custom manager but when I move the focus within it, BlackBerry throws an Uncaught: StackOverflowError. Do you know why this is happening?

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

Re: Handling Focus When Entering A Manager

Sounds like an infinite loop. Are you setting focus directly or scheduling it for later with invokeLater? I'd heartily suggest the latter.

----------------------------------------------------------
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.
Contributor
alfonsn
Posts: 34
Registered: ‎08-11-2011
My Carrier: Axis

Re: Handling Focus When Entering A Manager

I'm directly setting it on the onFocus method (without using invokeLater)...

Please use plain text.
Contributor
alfonsn
Posts: 34
Registered: ‎08-11-2011
My Carrier: Axis

Re: Handling Focus When Entering A Manager

[ Edited ]

Okay. I tried it again with invokeLater and it works. But I'm curious to why setFocus needs to be called with invokeLater. Why can't I just do it directly?

 

Anyway, thank you very much for your answer.

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

Re: Handling Focus When Entering A Manager

I can only guess that any setFocus (either by the framework due to navigation or programmatically) invokes all relevant onFocus/onUnfocus methods before actually changing focus. So in your case the setFocus inside onFocus calls your Manager's onFocus again... and again... and again.

 

invokeLater, on the other hand, postpones the action within to the time when focus setting has completed. At this focus you only shift the focus inside the Manager, so its onFocus is no longer called (the target field's onFocus, though, will be invoked before setting the focus to that field).

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