SS06Dec86
SS06Dec86

Reputation: 209

How to move to next input field when enter key is pressed in multiline edittext?

I am using an editText for taking description from user, what i want is that user can enter the description and when he presses enter key, the focus will move on to next input field, instead of adding a new line in description editText. How to achieve this?? The editText i am using is:-

<EditText
                    android:id="@+id/descriptionEditText"
                    android:layout_width="fill_parent"
                    android:layout_height="200px"
                    android:layout_gravity="center_vertical"
                    android:layout_marginBottom="20px"
                    android:layout_marginLeft="10px"
                    android:layout_marginTop="20px"
                    android:background="@drawable/edittext_modified_states"
                    android:cursorVisible="true"
                    android:gravity="left|top"
                    android:hint="Description"
                    android:padding="10px"
                    android:textColor="@color/black"
                    android:textCursorDrawable="@null"
                    android:textSize="30px"
                     />

Upvotes: 0

Views: 5587

Answers (4)

Mahendra Liya
Mahendra Liya

Reputation: 13218

Worth considering the below option when EditText is singleLine:

android:imeOptions="actionNext"

Upvotes: 0

vipul mittal
vipul mittal

Reputation: 17401

You can use textwatcher class to look for enter and then request focus to next edit text

 descriptionEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {

            // TODO Auto-generated method stub
        }
    });

Upvotes: 0

Piyush
Piyush

Reputation: 18933

You can use simply this:

 urEditView.setNextFocusDownId(R.id.id_of_edit_where_you_want_to_focus);

 urEditView.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on Enter key press
                urEditView.clearFocus();
                urnewEditText.requestFocus();
                return true;
            }
            return false;
        }
    });

Upvotes: 2

kathir
kathir

Reputation: 489

final EditText remark = new EditText(MyClass.this);    
remark.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);

Use this alike , that wat you need i think.

Upvotes: 0

Related Questions