oriharel
oriharel

Reputation: 10468

Android onKey is not fired for soft keyboard on a nexus one

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?

Upvotes: 0

Views: 1332

Answers (1)

Damian
Damian

Reputation: 8072

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             
   }
});

Upvotes: 2

Related Questions