开发者

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

开发者 https://www.devze.com 2023-01-29 11:31 出处:网络
I\'m trying to catch onKey events from a soft keyboard. however, on开发者_开发问答ly few keys fire the onKey event (Delete, back, etc.). not regular characters. anyone know why?If you\'re trying to ca

I'm trying to catch onKey events from a soft keyboard. however, on开发者_开发问答ly few keys fire the onKey event (Delete, back, etc.). not regular characters. anyone know why?


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

精彩评论

暂无评论...
验证码 换一张
取 消