java - developer.android.com 上的 editText.setOnEditorActionListener 错误

标签 java android

我在 developer.android.com 上看到这段代码用于处理软键盘的 IME_ACTION:

EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_SEND) {
            sendMessage();
            handled = true;
        }
        return handled;
    }
});

如果您看到,此代码无法正常工作,因为 OnEditorActionListener 方法适用于 TextView 类型...

那么,处理软键盘的 IME_ACTION 的正确方法是什么?

最佳答案

请改用 ButterKnife

@OnEditorAction(R.id.editText)
protected boolean actionDo(int actionId){
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        doCalculate();
        return true;
    }
    return false;
}

有效!

关于java - developer.android.com 上的 editText.setOnEditorActionListener 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24337909/

相关文章:

java - 在 Android 上覆盖应用程序并删除数据库

java - logger4j IsTracingEnabled

java - UML - 如何插入来自 java 类的对象属性?

android - 安卓 Jni 教程

android - 在 Android 中使用 Glide 显示图像。看不到任何东西

java - 在 Java 中读取 ini 文件时出现问题

java - OPENGL - 保持对象的原始纵横比

android - 线性布局与相对布局

android - 安卓设备位置图

java - 在 Eclipse 中使用 Adob​​e Air 的证书