09-24-2009 09:17 AM
09-24-2009 09:37 AM
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.