OnEditorActionListener with imeOptions actionNext not working

2.2k Views Asked by At

Here is my code:

<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>

and the Java code:

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;
        }
    });`

Unfortunately when I press the next button on the keyboard nothing happens. The cursor doesn't jump to the next field. I can't see what I am missing

2

There are 2 best solutions below

3
Wasim K. Memon On BEST ANSWER

As per doc

IME_ACTION_NEXT

Bits of IME_MASK_ACTION: the action key performs a "next" operation, taking the user to the next field that will accept text.

So it means it will focus on next focusable object like edittext or auto complete text view. so if no other object can get focus it will not move focus.

1
rafsanahmad007 On

use android:inputType="text" for your TextInputEditText

try calling view.requestFocus(); in your action .

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
    }
});