10-09-2011 02:07 PM - last edited on 10-09-2011 02:10 PM
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.
Solved! Go to Solution.
10-10-2011 03:36 AM
10-13-2011 07:54 AM - last edited on 10-13-2011 08:53 AM
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?
10-13-2011 09:34 AM
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.
10-13-2011 10:39 AM
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?
10-13-2011 11:13 AM
Sounds like an infinite loop. Are you setting focus directly or scheduling it for later with invokeLater? I'd heartily suggest the latter.
10-13-2011 11:21 AM
I'm directly setting it on the onFocus method (without using invokeLater)...
10-13-2011 11:33 AM - last edited on 10-13-2011 11:34 AM
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.
10-13-2011 11:54 AM
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).