Android “处理”;输入“;果冻豆钥匙

Android “处理”;输入“;果冻豆钥匙,android,keyboard,handle,enter,Android,Keyboard,Handle,Enter,我正在制作一个应用程序,在这个应用程序中我有编辑文本。我想当用户写一些文字在编辑文字结束,然后按回车按钮,我想它调用一些命令。这就是我所做的。这在ICS中是可行的,但当我在其他设备(果冻豆)上尝试时,它不起作用 inputViaTextChatbot.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, Key

我正在制作一个应用程序,在这个应用程序中我有编辑文本。我想当用户写一些文字在编辑文字结束,然后按回车按钮,我想它调用一些命令。这就是我所做的。这在ICS中是可行的,但当我在其他设备(果冻豆)上尝试时,它不起作用

inputViaTextChatbot.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
                // hide the keyboard  
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                // process 
                getThis = inputViaTextChatbot.getText().toString();
                if (getThis!=null && getThis.length()>1) {  
                    try {
                    Log.v("Got This: ", getThis);
                    } catch (IllegalStateException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    inputViaTextChatbot.setText("");  
                }
            }    
            return false;
        }
    });

有人能帮我做这件事吗?

这是一个已知的错误,它使
Enter
键在多台设备上无法识别。避免并使其工作的解决方法如下:

创建一个
TextView.OnEditorActionListener
,如下所示:

TextView.OnEditorActionListener enterKey = new TextView.OnEditorActionListener() {
  public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_GO) {
      // Do whatever you need
    }
    return true;
  }
};
例如,假设您的
视图
是一个
编辑文本
,您需要这样设置:

final EditText editor = (EditText) findViewById(R.id.Texto);
editor.setOnEditorActionListener(enterKey);
最后一步是将以下属性指定给
EditText

android:imeOptions="actionGo"
这基本上改变了enter键的默认行为,将其设置为
actionGo
IME选项。在处理程序中,只需将您创建的侦听器分配给它,这样您就有了
enter键
行为