Home » Android » How to add "Next" on android keyboard

How to add "Next" on android keyboard

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’ve seen in some applications that in the keyboard appears a Button called next that puts the focus on the next Edit Text. I want to add this in my application, Do you know how I can do it? Or it’s only on the application’s keyboard? Thanks a lot.
Sorry, I haven’t more information about this.

How to&Answers:

You just have to use the imeOptions tag in your layout. See imeOptions in docu.

<EditText
    android:id="@+id/someField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionNext"/>

Answer:

In the layout of edittext add android:imeOptions attribute. Here you can add different action buttons like Go, Search , Send , Next, Done etc. But to use this the EditText has to be a singleLine Else there will be an enter button there. So also use the android:singleLine="true".

So here is your solution

<EditText
    android:id=//put ur id
    android:layout_width=//according to need
    android:layout_height=//accordintoneed
    android:imeOptions="actionNext"
    android:singleLine="true"/>

EDIT

for addition i should add some more for future use or for the help of others..

You can handle the imeoption actions from your code. for that you have to set setOnEditorActionListener to the Edittext and when a action is pressed you can get it on public boolean onEditorAction(TextView v, int actionId, KeyEvent event) method. and if you not handle the code by yourself the imeoptions action will do the default action (usually going to next control).

Here is an example code for handling the action

EditText e = (EditText)findViewById(R.id.editText1);
e.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                 if (actionId == EditorInfo.IME_ACTION_NEXT ) {
                            // handle next button
                    return true;
                 }  
                 return false; 
        }
    });

Answer:

You have to add these two line given below in your EditText

android:imeOptions="actionNext"
android:singleLine="true"

Answer:

i tried all those answers posted here but none actually work. gladly I found myself a solution for this.

         <EditText
            android:id="@+id/etRegisterFirstName" 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Firstname"
            android:imeOptions="actionNext"
            android:inputType="textCapWords"
            android:maxLines="1" />

        <EditText
            android:id="@+id/etRegisterLastName" 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Lastname"
            android:imeOptions="actionNext"
            android:inputType="textCapWords"
            android:maxLines="1" />

Please do notice that I ADD android:inputType. Thats it .

Cheers / Happy coding