0

I'm trying to catch onKey events from a soft keyboard. however, only few keys fire the onKey event (Delete, back, etc.). not regular characters. anyone know why?

oriharel
  • 10,418
  • 14
  • 48
  • 57
  • Are you executing this while in a TextView? If your cursor is in a TextView it will not trigger the event. The back, home etc are special cases. – glr Dec 05 '10 at 13:10
  • I second that gyller, If you are using a EditText try implementing your logic with TextWatcher interface. – Shardul Dec 05 '10 at 13:49
  • Thanks. will try the TextWatcher approach – oriharel Dec 05 '10 at 14:52

1 Answers1

2

If you're trying to capture normal keystrokes from an EditText view, you'll need to use the following method to listen for key presses. Your onTextChanged method will get fired on each keypress allowing you to do whatever you need to do.

mEditText.addTextChangedListener(new TextWatcher(){
   @Override
   public void afterTextChanged(Editable editable){             
   }
   @Override
   public void beforeTextChanged(CharSequence text, int start, int count, int after){               
   }
   @Override
   public void onTextChanged(CharSequence arg0, int start, int before, int count) {
      //doStuff             
   }
});
Damian
  • 8,062
  • 4
  • 42
  • 43