OnEditorActionListener与imeOptions actionNext不起作用

时间:2017-03-09 17:25:44

标签: android imeoptions

这是我的代码:

<android.support.design.widget.TextInputLayout
        android:id="@+id/mylayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/some_layout">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/myid"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:hint="@string/some_hint"
            android:imeOptions="actionNext"
            android:inputType="time"
            android:maxLength="@integer/max_input_length"
            android:maxLines="1"
            android:singleLine="true"
            android:textSize="15sp"/>
    </android.support.design.widget.TextInputLayout>

和Java代码:

myField = (TextInputEditText) findViewById(R.id.myid);
    myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
                Log.d(TAG,"next");
                //Do something
                handled = true;
            }
            Log.d(TAG,"handled: "+handled);
            return handled;
        }
    });`

不幸的是,当我按下键盘上的下一个按钮时,没有任何反应。光标不会跳转到下一个字段。 我无法看到我所缺少的东西

2 个答案:

答案 0 :(得分:0)

android:inputType="text"

使用TextInputEditText

尝试在您的操作中调用view.requestFocus();

myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_NEXT) {
            Log.d(TAG,"next");
            //Do something
            Log.d(TAG,"handled: "+handled);
            view.requestFocus() ;  //add focus to next view object
            return true;   //return true
        }
        Log.d(TAG,"handled: "+handled);
        return false;   //add return
    }
});

答案 1 :(得分:0)

根据文件

  

IME_ACTION_NEXT

     

IME_MASK_ACTION的位:操作键执行&#34; next&#34;操作,   将用户带到接受文本的下一个字段。

所以这意味着它将专注于下一个可聚焦对象,如edittext或自动完整文本视图。因此,如果没有其他物体可以获得焦点,它就不会移动焦点。