How to use OnKeyboardActionListener? - android

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.

Related

Android: input field does not fire event when hitting 'next' on keyboard

I have multiple input fields on a html page optimized for Android.
The problem is that the event "onchange" is not always triggered when 'next' is clicked on the virtual keyboard.
To me this seems to be a similar to issue 7459 of the Android browser:
http://code.google.com/p/android/issues/detail?id=7459
How can I circumvent or compensate this issue? I need to calculate and refresh another input field in the function calc() after the value of any of the fields has been changed. If available even Android specific events or behaviours can be used.
Thanks, Holger

Flash APIs for Android Platform

My usage is very limited. All i need to do is to invoke the soft keyboard from within my flash application. Is there anything I can do, without using a textfield or any such editable controls, which will pop up the keyboard.
Thanks
So basically you need to have some sort of object that is interactive (that is, a textfield or something similar) to call up the on screen keyboard. This is probably because flash needs to set the focus for typing to that object. The object needs to be of type or of base type (somewhere in inheritance) InteractiveObject. You used the requestSoftKeyboard() method. Check it out:
http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/display/InteractiveObject.html#requestSoftKeyboard()
http://blogs.adobe.com/cantrell/archives/2011/03/everything-new-in-adobe-air-2-6.html

How to show the soft numeric keypad without an input field?

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.

How to get an event for soft keyboard KEYCODE_DEL?

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

how to hook key event

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.

Categories

Resources