我在与最新的果冻豆仿真器的行为的问题。 我有几个EditTexts
在我的应用程序。 一个OnEditorActionListener
提供了特殊的处理,当用户按下键盘上的回车键。 这个工作,直到ICS,但现在对果冻豆听者回调方法onEditorAction()
不再被调用。 只有一个新行插入EditText
。
这可以被复制这种方式:
EditText testEditText = new EditText(context);
testEditText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.d(TAG, "onEditorAction() called");
return false;
}
});
addView(testEditText);
这是Jelly Bean中的错误吗? 或在模拟器? 或有行为被有意改变?
奇怪的是别人编写,该方法被调用,但意想不到的参数,在这里运行果冻豆一台Nexus 7: 空的KeyEvent和onEditorAction()actionid = 0(果冻豆/的Nexus 7)
如果别人发现了这个问题:
我测试了几次,并在果冻豆仿真器监听回调方法onEditorAction()确实不再被调用时,按键上的虚拟键盘输入。
正如我上面一个可能的解决方案或替代方法提的是与可用动作键中的一个来替换输入键。 那些依旧会触发onEditorAction()。 我还必须指定输入类型。
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_GO);
<EditText
...
android:imeOptions="actionGo"
android:inputType="text" />
下面是我做什么,这将覆盖所有类型的被按下Enter键:
override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean {
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL)
... // Enter pressed
在XML我只添加android:imeOptions="actionGo"
究其原因,根据文档:
https://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html#onEditorAction(android.widget.TextView,%20int,%20android.view.KeyEvent)
actionId INT:动作的标识符。 这将是要么你提供的标识,或EditorInfo#IME_NULL如果被称为由于回车键被按下。
文章来源: onEditorAction() is not called after Enter key has been pressed on Jelly Bean emulator