How to stop string editing and close the virtual keyboard without clicking screen (android)

430 views
Skip to first unread message

Ian Teune

unread,
Oct 27, 2012, 12:40:52 AM10/27/12
to codenameone...@googlegroups.com
I'm a hard time solving this one. I might just be overlooking something.

I have a TextField in a form. I have added commands to the action bar. When one of the commands in the action bar is clicked, I show a new form through Form.show. However, I'm guessing since the screen touch is not handled by cn1 (instead by the android action bar), the keyboard is still showing and the string is still being edited on the next form.

The screenshots provided show every step:
1) searching by inputting text in a TextField
2) selecting action bar menu
3) selecting "Home" and the keyboard and search text still being visible

How do I get rid of the search text and the virtual keyboard when showing the next form through the action bar commands?

-Ian
p1.png
p2.png
p3.png

Chen Fishbein

unread,
Oct 27, 2012, 3:22:13 AM10/27/12
to codenameone...@googlegroups.com
Hi,
Try to use this after the app is initialized:
Display.getInstance().setShowDuringEditBehavior(Display.SHOW_DURING_EDIT_ALLOW_SAVE)

It's not clear to me why the virtual keyboard hasn't been folded, to close it explicitly you can call 
Display.getInstance().setShowVirtualKeyboard(false);

Ian Teune

unread,
Oct 27, 2012, 12:35:36 PM10/27/12
to codenameone...@googlegroups.com
Thanks Chen, calling Display.setShowDuringEditBehavior fixed the problem.

-Ian



--
You received this message because you are subscribed to the Google
Groups "CodenameOne Discussions" group.
 
For more information about Codename One please visit http://www.codenameone.com/
 
To post to this group, send email to
codenameone...@googlegroups.com
To unsubscribe from this group, send email to
codenameone-discu...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/codenameone-discussions?hl=en?hl=en

Ian Teune

unread,
Oct 27, 2012, 3:12:25 PM10/27/12
to codenameone...@googlegroups.com
Display.setShowDuringEditBehavior fixed the initial problem, but now when I leave the app with the virtual keyboard showing by hitting the home button and then return to my app, the keyboard is still showing, but typing letters does not input the letters into the TextField. I have to reselect the TextField before the virtual keyboard actual starts inputting text into the TextField. This was not huge issue before adding the call to Display.setShowDuringEditBehavior, although it did happen every once in a while - but now it happens every time I leave my app with keyboard showing.

Attached is a screenshot that demonstrates what happens when I hit the home button and then return to my app while the keyboard was showing. The virtual keyboard remains, but typing 'g' does not result in the TextField being updated with 'g'.

-Ian
p4.png

Chen Fishbein

unread,
Oct 27, 2012, 3:40:45 PM10/27/12
to codenameone...@googlegroups.com
I wasn't able to reproduce this bug, I assume there might be a something mis-configured on your AndroidManifest.
Can you post your manifest or send it to me, I will try to help.

Akinniranye James

unread,
Sep 30, 2016, 10:48:44 AM9/30/16
to CodenameOne Discussions
Am trying to hide the keyboard before I show my dialog because the keyboard makes my dialog smaller even after it disappears,  Display.getInstance().setShowVirtualKeyboard(false); seems not to be working

Shai Almog

unread,
Sep 30, 2016, 9:23:00 PM9/30/16
to CodenameOne Discussions
try textField.stopEditing()

lai...@gmail.com

unread,
Nov 12, 2017, 11:43:33 AM11/12/17
to CodenameOne Discussions

On Saturday, October 1, 2016 at 4:23:00 AM UTC+3, Shai Almog wrote:
try textField.stopEditing()

On an android 7 phone in landscape orientation, if I touch TextArea, I get a fullscreen soft keyboard. When I press done on the keyboard, the edit area that is embedded in the keyboard overlay disappears, but the keyboard itself does not. If I at this point flip the device to get into portrait, the soft keyboard does not disappear like it normally does when changing orientation, but stays on, now showing my form in the top half of the screen. Typing with this phantom soft keyboard will not add text anywhere. clicking on the text area makes the keyboard functional again - pressing back key hides the keyboard. The soft keyboard in question is the Android AOSP keyboard, so should be pretty standard on many devices.

I believe the keyboard should hide when pressing done in landscape mode; I can not get it to hide even when trying to make a custom TextField that certainly does its best to make sure soft keyboard is hidden after done:

public class TextEdit extends TextField {
Form result;
TextEdit(Form f) {
Display.getInstance().setShowDuringEditBehavior(Display.SHOW_DURING_EDIT_ALLOW_SAVE);
result = f;
setSingleLineTextArea(false);
addActionListener(al -> {
            stopEditing();
            Display.getInstance().setShowVirtualKeyboard(false);
            result.revalidate();
            result.show();
});
setDoneListener(dl -> {
            stopEditing();
            Display.getInstance().setShowVirtualKeyboard(false);
            result.revalidate();
            result.show();
});
}
}
 

Shai Almog

unread,
Nov 13, 2017, 1:46:58 AM11/13/17
to CodenameOne Discussions
It's possible you are just seeing a next button and not a done button although doing field.putClientProperty("goButton", Boolean.TRUE); doesn't cause it to fold either which might be a misbehavior.

Your code mixes several concepts that it shouldn't e.g. setShowDuringEditBehavior isn't applicable in modern devices and should have been deprecated.

I would also suggest that you don't call revalidate/show without a verifiable reason.

I suggest trying to call stopEditing() in a call serially block but this won't work if you've already moved to a different text field as you'd need to invoke stop editing on that.

lai...@gmail.com

unread,
Nov 13, 2017, 2:08:12 AM11/13/17
to CodenameOne Discussions
Thank you for the quick answer. My verifiable reason to mix concepts and paranoidicly calling revalidates/shows is that it does not work :-)

Changing the class to:

public class TextEdit extends TextField {
Form result;
TextEdit(Form f) {
result = f;
final TextEdit te = this;
setSingleLineTextArea(false);
addActionListener(al -> {
Display.getInstance().callSerially(() -> { te.stopEditing(); result.show();});
});
setDoneListener(dl -> {
Display.getInstance().callSerially(() -> { te.stopEditing(); result.show();});
});
}

Still shows exactly the same behavior, and the ghost virtual keyboard still remains. The ghost keyboard also stays visible when I press home key to return the launcher.

lai...@gmail.com

unread,
Nov 13, 2017, 6:16:01 AM11/13/17
to CodenameOne Discussions
Setting build hint android.keyboardOpen = false will fix the issue (but make the UI less usable for other things). Will be ok for me, but this is certainly a bug when the keyboardOpen is true and there is no next text field to jump to for the done action; the keyboard should close in that case, rather than leaving a zombie typing area stomping around the application.

Shai Almog

unread,
Nov 14, 2017, 12:31:15 AM11/14/17
to CodenameOne Discussions
That might be a regression. Can you please file an issue with a test case?
Reply all
Reply to author
Forward
0 new messages