【发布时间】:2011-07-30 01:24:54
【问题描述】:
我有一个要监视 KeyEvents 的 EditText,并且我有一个侦听器设置如下:
mText = (EditText) this.findViewById(R.id.title);
mText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
final int view = v.getId();
switch (view) {
case R.id.title:
Log.d(LOG_TAG, "key handled");
break;
}
return false;
}
});
我的问题是,当使用虚拟键盘输入 EditText 时,触发记录的唯一按键是退格键。我已经验证所有其他按键甚至都没有触发onKey()。我确定这很简单,但在 SO 上没有找到任何似乎可以解决此问题的内容。
谢谢,
保罗
【问题讨论】:
-
来自文档
Key presses on soft input methods are not required to trigger the methods in this listener, and are in fact discouraged to do so. The default android keyboard will not trigger these for any key to any application targetting Jelly Bean or later, and will only deliver it for some key presses to applications targetting Ice Cream Sandwich or earlier.developer.android.com/reference/android/text/method/…
标签: android android-edittext keylistener