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.
Related
I know that you can specify a short message input type in order to turn the enter key of the keyboard into an emoji button and pressing it will show up the emoji list but what i want to do is open up the emoji list programatically from a button. Is this possible?
There is no functionality to add tabs to any generic keyboard. Certain keyboards may support it, but it isn't a common feature. You could write your own fully custom keyboard, but that's a lot of work and will piss off many users.
Also, I'm not sure what you mean about by like in hangouts. I use hangouts- it doesn't do anything odd with my keyboard. It stays as Swype, there's no special emoji tab. It may be a feature of your favorite keyboard based on the input type (I assume both use input type textShortMessage). But it isn't a generic feature.
See Link Android Keyboard with Emoji
Thanks and enjoy...
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.
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
Simply say, is there any example about 'OnKeyboardActionListener'?
I want to call my method, whenever user type any character on keyboard.
OnKeyListener or OnKeyDown is not called when the word is composing. <- it's a problem.
So, I'm trying to use 'OnKeyboardActionListener' to solve the problem above.
Simply say, is there any example about
'OnKeyboardActionListener'?
This interface is used in the creation of input method editors ("soft keyboards"). The SoftKeyboard sample that shipped with your SDK uses this interface.
I want to call my method, whenever
user type any character on keyboard.
If this is your own keyboard, follow the SoftKeyboard example.
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.