Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keyboard events for EditText not reaching my event handler.

 
Adam Schweitzer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic