Android setOnEditorActionListener无法正常工作

撒母耳记1

由于某些原因,setOnEditorActionListener无法正常工作。

我的目标SDK为22。

这是我的onCreate方法中的代码:

final EditText pageBox = (EditText) findViewById(R.id.pageBox);

    searchBox.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)) {

        }
      }
    });

这是xml:

<EditText
   android:layout_width="0dp"
   android:layout_height="wrap_content"
   android:id="@+id/searchBox"
   android:singleLine="true"
   android:hint="@string/string_find_player"
   android:layout_gravity="left"
   android:layout_weight="1" />

非常感谢所有帮助!

霸王龙

android:imeOptions="actionDone"由于要查找该代码(EditorInfo.IME_ACTION_DONE,因此应尝试将其添加到xml中

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/searchBox"
android:singleLine="true"
android:hint="@string/string_find_player"
android:layout_gravity="left"
android:layout_weight="1"
android:imeOptions="actionDone" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章