0

我希望我的回车键完成一个动作而不隐藏键盘。目前,每次我输入内容并按下回车按钮时,EditText 输入都会被清除以接受下一个输入,但是随着键盘消失,我必须再次单击 EditText,以便键盘再次出现......

现在这是我的布局:

<EditText
    android:id="@+id/etCommand"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/commandHint"
    android:inputType="textNoSuggestions"
    android:imeOptions="actionSend" >
</EditText>

和代码:

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

编辑

正如 swayam 建议的那样,我必须返回true内部onEditorAction,以便操作系统认为该操作已处理并不管它。

4

2 回答 2

0

试试这个代码片段:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
于 2012-08-30T16:30:15.377 回答
0

为 Enter 按键添加 EditText 的 KeyListener 并在任务完成后请求再次关注 edittext 将是解决方案

于 2012-08-30T17:45:09.613 回答