This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Android and the fly likes Keyboard events for EditText not reaching my event handler. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "Keyboard events for EditText not reaching my event handler." Watch "Keyboard events for EditText not reaching my event handler." New topic
Author

Keyboard events for EditText not reaching my event handler.

Adam Schweitzer
Greenhorn

Joined: May 26, 2006
Posts: 17
I added an OnKeyListener to an EditText widget.. the problem is, this event handler never gets called when tying in the widget. And I don't understand why. Can someone explain what I'm doing wrong?

Here is some sample code to illustrate what I'm trying to do. All it is supposed to do is fill a second text box with the value of the first. But it doesn't. (Clicking on the button, though, does function as desired - and the two event handlers have the same code).



and the associated layout:
Adam Schweitzer
Greenhorn

Joined: May 26, 2006
Posts: 17
Hi,
Can someone help me with this? I don't understand why this doesn't work - even the HelloFormStuff tutorial uses essentially the same code..
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

I can't find any bugs in the code and, at least over here, it's working as expected.
Everything I type in the first EditText field is duplicated in the second one.
Adam Schweitzer
Greenhorn

Joined: May 26, 2006
Posts: 17
I should elaborate a bit.
In the emulator, if you have not clicked on the first textbox prior to typing, it works as intended. If you click on the textbox and then type, it does not.
When deployed on a real device, it does not work either.

I have worked around this issue by using a TextWatcher (via addTextChangedListener() method of EditText) instead of an OnKeyListener.. but I have no clue why I am experiencing this behaviour.
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

I see it happening now, It's a problem (bug) of the soft keyboard. It's working fine with the keyboard using the emulator, but when you use the soft keyboard the listener is only called when you press return or delete. As far a I can see using the TextWatcher is the best workaround.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Keyboard events for EditText not reaching my event handler.