gpt4 book ai didi

android - OnEditorActionListener 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:32:29 24 4
gpt4 key购买 nike

我只是想在用户按下 editText 上的 enter 时捕获事件。

我没有收到 Toast 消息,不是“Enter pressed”,也不是“Some key pressed!”要么。

我做错了什么?

myEditText.setOnEditorActionListener(new OnEditorActionListener() {

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

Toast.makeText(getApplicationContext(), "Some key pressed!", Toast.LENGTH_LONG).show();

if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
Toast.makeText(getApplicationContext(), "Enter pressed", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});

编辑:

它在 Android 2.3.3 上运行,在 4.1.2 上运行不正常有什么想法可以让我在任何 Android 设备上运行吗?

最佳答案

请尝试将 EditText 设置为单行模式。

editText.setSingleLine();

或在您的 xml 布局文件中:

android:singleLine="true"

更新

android:singleLine="true" 已弃用。从现在开始,使用 android:maxLines="1"android:inputType="text" 来实现这个行为

editText.setMaxLines(1);
editText.setInputType(InputType.TYPE_CLASS_TEXT);

以编程方式设置。

关于android - OnEditorActionListener 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15901863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com