【问题标题】:Android. onEditorAction never called安卓。 onEditorAction 从未调用过
【发布时间】:2013-03-04 13:33:54
【问题描述】:

我试图捕捉从屏幕上移除键盘的事件,我正在使用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 做什么,无论我是开始编辑还是完成它,所需的方法都不会被触发。我做错了什么?

【问题讨论】:

    标签: java android xml android-edittext


    【解决方案1】:

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

    我以为是imeOptions,但不是。

    如果我设置android:inputType="text",它可以在我的平板电脑上运行。

    我假设它适用于其他 inputType。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-26
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      相关资源
      最近更新 更多