简体   繁体   English

Android(里程碑/ Droid):View.OnKeyListener无法正常工作?

[英]Android (Milestone/Droid): View.OnKeyListener not working correctly?

I am using a simple EditText and register an View.OnKeyListener . 我正在使用一个简单的EditText并注册一个View.OnKeyListener Some GUI changes should happen (fading in/out of views) when certain conditions for the EditView text apply. 当EditView文本的某些条件适用时,应该发生一些GUI更改(淡入/淡出视图)。 In the emulator, this works as expected. 在仿真器中,这按预期工作。 On the Motorola Droid/Milestone, the listener does not work, only 在Motorola Droid / Milestone上,监听器仅起作用

  1. after pressing DEL, the listener is called the first time and always afterwards 在按DEL后,第一次调用监听器,之后总是调用
  2. when activating the number input, the listener works correctly 激活数字输入时,侦听器正常工作

Note: I deactivated the suggestions with TYPE_TEXT_FLAG_NO_SUGGESTIONS and used the IME action IME_ACTION_GO to have a workaround for this (otherwise the user could not "start" a request). 注意:我使用TYPE_TEXT_FLAG_NO_SUGGESTIONS停用了建议,并使用IME操作IME_ACTION_GO来解决此问题(否则用户无法“启动”请求)。

找到了一种更好的工作方式来实现此目的:将EditText.addTextChangedListenerTextWatcher类一起使用(并实现TextWatcher.onTextChanged(CharSequence s, int start, int before, int count) ),在Milestone / Droid上也可以完美地工作。

TextWatcher cannot fully replace onKeyListener. TextWatcher无法完全替换onKeyListener。 For example, if your textbox is empty, how would you detect that user pressed DEL key? 例如,如果您的文本框为空,您将如何检测到该用户按下了DEL键? Or, what if you don't have textbox at all and you want to detect key events? 或者,如果您根本没有文本框并且想要检测关键事件该怎么办?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM