I'm creating a search component and as a user moves off the miniKeyboard, I want the focus to move to a Submit button. I'm finding that some widgets are not responding to "hasFocus()" even though setFocus(true) works fine. It's important to note this function doesn't come back as invalid...
Here's the code:
Function onKeyEvent(key as String, press as Boolean) as Boolean if press then print "KEY: "; key ' Just to remove any question that we have focus! m.miniKeyboard.setFocus(true) print "KEYBOARD FOCUS: "; m.miniKeyboard.hasFocus() if (key = "down") and (m.miniKeyboard.hasFocus() = true) m.searchBtn.setFocus(true) return true end if end if
return false End Function
Output after pushing "down" from the last button in the miniKeyboard.
KEY: down KEYBOARD FOCUS: false KEY: down KEYBOARD FOCUS: false
Your code will fail if m.searchBtn is out of scope or is being seen as the wrong type. You can test this by placing a STOP after print "KEYBOARD FOCUS: "; m.miniKeyboard.hasFocus() and then do a print m.searchBtn in the debugger to see what it thinks it is.
What you're trying to do does work if the search button is appended as a child to the minikeyboard - it makes it a bit simpler at least in my experience, besides, you probably want to reset the position to "a" each time the search window is initiated instead of keeping the selection on the last item highlighted - consider that a bug with the keyboards that they need to be destroyed and recreated to fix that issue.
m.searchscreen.translation=[668,170] If m.devicemodel="4200X" m.SearchScreen.GetChild(2).keyboardBitmapUri="pkg:/images/search.png" Else m.SearchScreen.GetChild(2).keyboardBitmapUri="pkg:/images/searchfhd.png" End If
If m.searchscreen.visible=TRUE 'Handle search screen keys If key="up" If m.searchscreen.getchild(1).hasFocus() m.searchscreen.getchild(2).SetFocus(TRUE) End If Else If key="down" If Not m.searchscreen.getchild(1).hasFocus() m.searchscreen.getchild(1).SetFocus(TRUE) End If End If End If
SearchActivated callback - for when the button is selected from the search screen
temp=m.searchscreen.getchild(2).Text m.SearchScreen.visible=FALSE ' make search screen disappear from display
'do what you want to do with the search term and display results or no results 'remember to setfocus the new screen with the results or no results End Function
Note in the code above, the Search Button has a higher z-order in creation than the mini keyboard. First it draws a black rectangle background for the text entry box Second it draws the Search Button Third it draws the mini Keyboard on top of both of those
It could be your code is correct but the order is wrong, or you are seeing a race condition where it is taking longer to set the focus between the two objects in your code, or it could simply be a bug in the firmware, but go ahead and try making some changes to see if it resolves it for you.
Thanks for the help. I was able to get it working by the following, below. It appears if the button is a child of the miniKeyboard, which it was, it's tracked by the "focusedChild" item.
if press then 'm.searchBtn.setFocus(true) if (key = "down") and (m.miniKeyboard.focusedChild.id = "") m.searchBtn.setFocus(true) return true else if (key = "up") and (m.miniKeyboard.focusedChild.id = "searchBtn") m.miniKeyboard.setFocus(true) return true end if end if