I am developing an Android application that makes use of EditText (Multiline). The devices I am testing it on lack hard keyboards, so as a result I (obviously) use the soft keyboard. When I touch/click on the EditText the soft keyboard appears. The functionality I intend for the EditText is that when I press "Enter" the soft keyboard dissappears. However, to indicate a paragraph I want to use "Shift-Enter". It's kind of like when typing comments on facebook.
I have been able to imitate the "Enter" functionality with some simple code. By using a KeyEvent and OnKeyListeners. I tried to code it so that "Shift-Enter" would work (e.g. isShiftPressed()). However, after doing some research I found out that "Shift" aparently doesn't trigger a onKey event for soft keyboards.
A lot of the StackOverflow suggestions tell me to use TextChangedListener, but this doesn't work for me because neither shift nor enter actually changes the text in the EditText.
Does anyone know a solution so that I can get the intended function of my EditText? Anything will do at this point I think.
Related
I want to press "?123" key programmatically. But I don't know the KEYCODE for this symbol. And I also unable to find it. Can anybody know the KEYCODE for "?123" symbol on Soft Keyboard.
It's not an actual key press.
It's just a way for the user to change the keyboard layout to be able to press on symbols etc.
I think it's not even a guarantee that every keyboard has it. There are many custom keyboards on Android and they can make it any way they want it.
You should think for yourself, what are you actually trying to achieve? to insert a "#" for example? then you should just simulate the keycode for that.
If you want to customize at this point, I think you should create a input method from the beginning, with your own keyboard class and own keyboardView.
This way you can do whatever you want in the keyboard.
How to make a Android custom keyboard?
I'm having the following issue - I have placed
android:windowSoftInputMode = "stateAlwaysVisible"
in my manifest which works relatively fine since the software keyboard is almost always visible. I have a webview in which I have an editable div in which the user can enter text. However when the user have entered some text and taps somewhere else on the webview(on a position different from the current cursor position) the software keyboard will hide for a moment and afterwards reappear. I'm at my wits end and can't find an explanation for this. Using InputMethodManager to make the keyboard always visible also didn't help.
Any help will be greatly appereciated. Thanks!
The issue was that the keyboard is hiding due to the fact that we were passing all the touch events down to javascript we are having via loadUrl("javascript : bar(event.getX(), event.getY()));".
Turns out the loadUrl method internally hides the software keyboard. I worked this around by not passing the touch events to the javascript, but instead by using window.onmousemove
I have an OpenGL application that needs to show the soft keyboard for devices without physical ones for user input such as username or numbers in a few cases. In the case of numeric input, is there any way to show the numeric keypad instead of the alphabetic keyboard? I'm not using any text edit fields or anything, just the InputMethodManager:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(glView, InputMethodManager.SHOW_FORCED);
The only method I've found that looks remotely helpful is InputMethodManager.setInputMethod but that takes an IBinder token and a String id, neither of which is explained very well in the documentation. I get the impression that it's not the right way to go, though.
If I were using an edit field, it would be simple and obvious, and I've found dozens of answers for that, but that's not what I'm doing, because it's an OpenGL game, so I have to just displaying the keyboard manually as above.
Probably not the answer you are looking for since it is more of a hack than a real solution, but a few things come to mind that might work (that is if you can't get a real solution).
An EditText with View.INVISIBLE set. Although, you might not be able to set focus here.
Put an EditText behind your GLSurfaceView and focus it. So it’s technically visible (from a code standpoint) but invisible to the user.
I asked this previously on the Android dev mailing list but got no reply.
In my application, I bring the soft keyboard on from time to time, and
it looks like events for the DEL key are not delivered. The method in
question is at
http://pastebin.com/zZaZWJ4t
and the whole Java class is at
http://squeakvm-tablet.googlecode.com/hg/project/src/org/squeak/android/SqueakView.java
Any alphanumeric key or Enter (Return) tapped on the soft keyboard is
passed to the application except for KEYCODE_DEL. I tried to replace
KEYCODE_DEL in the case clause with anything else (e. g. with code for
for hardware button PAGE_UP), and the clause takes control when that
button is pressed.
I did not subclass the Android Keyboard class, just used the default
input manager.
What can be done in order to receive events for KEYCODE_DEL? Is
deriving a keyboard subclass the only way?
Thanks.
I had a similar issue and I was able to solve it by adding a TextWatcher to EditText using addTextChangedListener.
Your onCreateInputConnection() override is not returning TYPE_NULL as the input type. You must use TYPE_NULL to be assured that key events will be generated. They are in fact generated for some keys and not for others, in some versions of Android but not others, but there is nothing that you can count on about that unless you use TYPE_NULL.
If you do adjust your code to use TYPE_NULL, then please see this description of a workaround for two bugs in certain versions of the default LatinIME Google Keyboard that affect TYPE_NULL processing:
Android - cannot capture backspace/delete press in soft. keyboard
I'd like to limit the text length of EditText widget,
And if user type more charactes than the limited length,
I want to show a kind of warning popup, however I can't show popup.
The problem is that we can't show popup while typing,
Probably, many people think a way of utilizing OnKeyListener or OnKeyDown.
But, when the word is composing, nothing come into OnKeyListener or OnKeyDown,
So, we can't show popup when we want to.
Is there anyone who have smart idea to solve this problem?
You should be able to remove focus from the widget, and show your message.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);
OnKeyboardActionListener is for implementing software keyboards.
OnKeyListener and OnKeyDown do not get called, as you have discovered, when using a software keyboard. They only get called when using a hardware keyboard, which many Android devices don't even have.
I assume what you are trying to do is capture key events as they are occurring in an EditText area. Your best bet in this case, in order to handle both software keyboard input and hardware keyboard input, is to register a TextWatcher via the addTextChangedListener() method.
Note that on phones with Android 2.1 and later, such as the Nexus One, people have the option of using speech recognition to input text into your EditText instead of typing the text. When they do that you may get full words, or even full sentences, entered all at once. So you need to check the entire contents of the EditText field when there is a change to the contents.