Change behavior of action key android with imeOptions doesnt work

301 views Asked by At

i try to jump from a TextView element to the next editable Object in my Android activity. The next Object is a element of ListView, which is editable. I tried to use the imeOptions but it still performs a newline in the TextEdit Object. My XML looks like this:

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:hint="@string/question_hint"
            android:id="@+id/questionField"
            android:textColor="@color/text_color"
            android:textCursorDrawable="@null"
            android:maxLength="@integer/question_length"
            android:imeOptions="actionNext"/>
        <!--android:minLines="2"-->

I also added a codeline in the oncreate method of the activity:

questionField = (EditText) findViewById(R.id.questionField);
questionField.setImeOptions(EditorInfo.IME_ACTION_NEXT);

But it doesnt work. Anyone has an idea? Thanks

1

There are 1 answers

2
tim.paetz On

Try something like this:

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

                    if ((actionId == EditorInfo.IME_ACTION_DONE
                            || actionId == EditorInfo.IME_ACTION_NEXT
                            || actionId == EditorInfo.IME_ACTION_GO
                            || (event != null
                                    && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)))
                    {

                        return nextView.requestFocus()  // the next view you want the focus to be on
                    }
                    else
                    {
                        return false;
                    }
                }
            });