Android native keyboard onShowComplete

64 views
Skip to first unread message

Curtis

unread,
May 29, 2014, 12:19:42 PM5/29/14
to codenameone...@googlegroups.com
I am have some trouble controlling when the keyboard comes up. What I want to do is have the native keyboard to appear with the focus in a particular input field when I show a certain Form. The user is cycling through a list and imputing values. For each value a new Form appears. The user cycles through the Forms with a Back button, a Next button, Done on the keyboard native keyboard, or a event listener for a barcode scanner.

The current solution I have is by simulating a click in the onShowCompleted()

@Override
   protected void onShowCompleted() {
       countedTextField.pointerPressed(0, 0);
       countedTextField.pointerReleased(0, 0);
   }

This works for when I use the Back, Next, or Done because the keyboard will close automatically on clicking on a button on the form or through the done button on the keyboard. However when the switch is made by the barcode scanner, just a listener,  it seems like it loads the new Form and then lowers the keyboard after the onShowCompleted and the pointerPressed/Released have no effect. 

I tried a few ways of trying to detect if the keyboard is up by checking the display height but it lead to very inconsistent results. I have also tried to make a native android interface to force the keyboard to lower but I was not able to get that to work properly. 

Any ideas of how to get the keyboard to automatically come up upon showing a form or to force the keyboard to lower if it is up?



Shai Almog

unread,
May 30, 2014, 2:06:13 AM5/30/14
to codenameone...@googlegroups.com, curtis.w...@actiontrak.com
Checking the display height will only work on Android and even there its problematic since the display changes asynchronously.
On iOS the size of the display doesn't change when editing.

To trigger editing we have the Display.editString() API that allows you to initiate the native text editing on a text area/field.
Calling this to trigger "next" might be problematic though since you might enter a recursive situation.

Make sure to only use this API from the EDT and not from a separate thread.
Reply all
Reply to author
Forward
0 new messages