Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add "Next" on android keyboard

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.

like image 638
jramirez Avatar asked Dec 09 '12 16:12

jramirez


People also ask

How to add Next button in keyboard android?

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

How do I change the focus to next text in android?

setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (edtPasscode3. getText(). length() == 1) edtPasscode4. requestFocus(); return false; } });

How to add text field in android?

Click on the "Plain Text" label, and drag it to your designer. If you click on the button below, you will see the xml code. The textbox is called EditText.


4 Answers

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; 
        }
    });
like image 181
stinepike Avatar answered Sep 19 '22 21:09

stinepike


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"/>
like image 45
Vajk Hermecz Avatar answered Sep 21 '22 21:09

Vajk Hermecz


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

android:imeOptions="actionNext"
android:singleLine="true"
like image 28
Omar Faroque Anik Avatar answered Sep 19 '22 21:09

Omar Faroque Anik


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

like image 33
ralphgabb Avatar answered Sep 20 '22 21:09

ralphgabb