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

Posts: 17,003
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How can I remove the focus from my field programatically?

you can try to call moveFocus on the manager manually.
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
Posts: 157
Registered: ‎02-18-2009
My Device: Not Specified

Re: How can I remove the focus from my field programatically?

Perhaps some background info of what field I'm working on will help make it more clear what I need.

I try to duplicate the behavior of email edit field used by the BlackBerry email client. When the user enters a character a box popups showing all matching contacts. When the user selects a contact that contact is set in the edit field and the focus shifts to the next field. The click event needs to be handled by my control because it needs to set the edit field with the selected contact (the name of the contact). Then the focus must shift to the next field (just like it does with the BB email application). What the best field to put the next focus on is something the BB system already knows because it knows about fields and their ordering.


Now I can use moveFocus but than I need to known which field requires focussing. That means I need to duplicate the functionality which the BB already has (but is not accessible to me). Then there is nextFocus but I guess this only works for one manager and not across managers (when you have multiple nested managers getting the next focussable field is not completely clear).


I tried setting the focus using:



public static void advanceFocus(Manager manager) { if (manager == null) { return; } int focusIndex = manager.getFieldWithFocusIndex() + 1; Field found = null; for (int i = focusIndex; i < manager.getFieldCount(); i++) { Field field = manager.getField(i); if (field.isFocusable()) { found = field; break; } } if (found == null) { /* * Not found recursively try parent */ advanceFocus(manager.getManager()); } else { found.setFocus(); } }

 Which should work across managers. This kind of works, ie. the next element is focussed, but there is still a problem with this approach. Sometimes, after changing the focus with this method, the BB popups some sort of system menu similar to the menu you get when you select the BB menu key. Somehow the popup gets triggered when the focus is changed with the above procedure. It's unclear to me why and when the popup happens but it's easy to reproduce.