7

我试图捕捉从屏幕上移除键盘的事件,我正在使用OnEditorActionListener类。但是,它的onEditorAction方法永远不会被调用。

这是我在 XML 中的 EditText:

<EditText
    android:id="@+id/editTextSearch"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="50dp"
    android:layout_weight="0.05"
    android:background="@color/white"
    android:ems="10">
</EditText>

这就是我在 java 文件中使用它的方式:

private void createTextEdit()
{
    EditText searchTextField = (EditText)findViewById(R.id.editTextSearch);
    searchTextField.addTextChangedListener(new TextWatcher()
    {
        public void afterTextChanged(Editable s)
        {
           System.out.println("AFTER TEXT CHANGED");                                                             
        }
        public void beforeTextChanged(CharSequence s,
        int start, int count, int after)
        {
             System.out.println("BEFORE TEXT CHANGED " + s);
        }

        public void onTextChanged(CharSequence s,
                int start, int before, int count)
        {
            System.out.println(s);
        }
    });

    searchTextField.setOnEditorActionListener(new OnEditorActionListener()
    {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
        {

            System.out.println("ACTION ID " + actionId);//NEVER CALLED

            if(actionId == EditorInfo.IME_ACTION_DONE)
            {
                System.out.println("ACTION DONE!!!!!!!!!!");
                return true;
            }

            return false;
        }
    });

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(searchTextField, InputMethodManager.SHOW_IMPLICIT);
}

无论我searchTextField是开始编辑还是完成它,都不会触发所需的方法。我究竟做错了什么?

4

1 回答 1

1

在 Nexus 7 上也有同样的问题。

我以为是imeOptions,但不是。

如果我设置它可以在我的平板电脑中使用android:inputType="text"

我假设它适用于其他 inputType。

我认为这是 Nexus 上的一个错误。

于 2015-06-13T15:29:07.563 回答