Setting EditText imeOptions to actionNext has no effect
Asked Answered
H

15

105

I have a fairly complex (not really) xml layout file. One of the views is a LinearLayout (v1) with two children: an EditText(v2) and another LinearLayout(v3). The child LinearLayout in turn has an EditText(v4) and an ImageView(v5).

For EditText v2 I have imeOptions as

android:imeOptions="actionNext"

But when I run the app, the keyboard's return does not check to next and I want it to change to next. How do I fix this problem?

Also, when user clicks next, I want focus to go to EditText v4. I do I do this?

For those who really need to see some code:

<LinearLayout
        android:id="@+id/do_txt_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/col6"
        android:orientation="vertical"
        android:visibility="gone" >

        <EditText
            android:id="@+id/gm_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="@drawable/coldo_text"
            android:hint="@string/enter_title"
            android:maxLines="1"
            android:imeOptions="actionNext"
            android:padding="5dp"
            android:textColor="pigc7"
            android:textSize="ads2" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/rev_text"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/coldo_text"
                android:hint="@string/enter_msg"
                android:maxLines="2"
                android:padding="5dp"
                android:textColor="pigc7"
                android:textSize="ads2" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:background="@drawable/colbtn_r”
                android:clickable="true"
                android:onClick=“clickAct”
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:src="@drawable/abcat” />
        </LinearLayout>
    </LinearLayout>
Helfrich answered 12/4, 2014 at 22:27 Comment(3)
I'm not sure this will work for views that are not siblings, but you can try adding android:nextFocusDown="@id/edit_text_v4" (also maybe try android:nextFocusForward or some of the other nextFocus attributes).Culminant
@Culminant it didn't work. Notice that the next button is not showing up at all. The button is still the return button.Helfrich
@KatedralPillon Did you manage to solve it ? If yes then can u post your solution here ? I am facing the same issue.Crabb
Q
226

Just add android:maxLines="1" & android:inputType="text" to your EditText. It will work!! :)

Quinonez answered 6/6, 2014 at 15:23 Comment(14)
doesn't work in my case. :\ <EditText android:id="@+id/loginEmail" android:layout_width="match_parent" android:layout_height="match_parent" android:hint="username" android:singleLine="true" android:imeOptions="actionNext" android:nextFocusDown="@+id/loginPassword"/>Farceuse
Try setting your EditText's height as wrap_content.Quinonez
@TeodorKolev Try setting your EditText's height as wrap_content.Quinonez
Not working also with wrap_content . Setting an inputType solved the problem in my case.Bixler
This works, but now the EditText scrolls to the right instead of going to the next line automaticly when it hits the right side of the screen. I would like the Edit text to scroll vertically instead and start on a new line when it runs out of space. How do I do this?Tutti
@Tutti Did u try setting inputType ="text" and android:singleLine="true"?Quinonez
I ended up writing android:imeOptions="actionDone" android:inputType="text" and writing mEditTextAnswer.setHorizontallyScrolling(false); and mEditTextAnswer.setLines(6); inside the onCreateTutti
use android:maxLines="1" instead of android:singleLine="true" as its deprecatedCheri
android:maxLines="1" android:lines="1" android:imeOptions="actionNext" Its not workingHerrah
Although,` android:singleLine="true"` is deprecated but some how does the trick, while maxLine="1" does not working.Exciseman
You must set the inputType="text" to make imeoptions work.Feeble
It is actually mandatory to add inputType attribute for this to work. Thanks for the heads up!Druse
what if your input type is numeric?!!??!?!Goulet
@Bixler setting an inputType worked for me, thanks for commenting.Pansie
S
51

singleLine is deprecated. Adding an input type (eg: android:inputType="text") also worked for me.

Use android:maxLines="1" as singleLine is deprecated

Steersman answered 5/6, 2016 at 22:58 Comment(1)
This is the correct answer!! imeOptions and maxLines will have no effect without inputTypeAmpereturn
C
43

android:singleLine has been deprecated, it is better to combine android:maxLines="1" with android:inputType="text". This would be the code:

<EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:maxLines="1"
        android:inputType="text"
        />
Cloyd answered 3/11, 2015 at 6:57 Comment(0)
M
31

The answers given here were all very helpful, but I was still struggling to get my keyboard's "Next" to show.

Turns out that when you use Android's android:digits attribute in your XML, it prevents the android:imeOptions="actionNext" from working as expected.

The answer is actually to use the deprecated android:singleLine="True". This seems to force the IME Option to be respected.

Old, Non-Working Code

        <android.support.design.widget.TextInputEditText
            android:id="@+id/first_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
            android:ellipsize="end"
            android:hint="@string/first_name"
            android:imeOptions="actionNext"
            android:inputType="textCapWords"
            android:maxLength="35"
            android:maxLines="1" />

Working Code

        <android.support.design.widget.TextInputEditText
            android:id="@+id/first_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
            android:ellipsize="end"
            android:hint="@string/first_name"
            android:imeOptions="actionNext"
            android:inputType="textCapWords"
            android:maxLength="35"
            android:maxLines="1"
            android:singleLine="true" />

I'm not a fan of using a deprecated attribute, but for now it seems to get the desired result.

Maritamaritain answered 10/10, 2017 at 20:52 Comment(1)
thanks deprecated but it's working !! any issue will occur in future?Montmartre
H
13

single line deprecated so you add below code I think inputType must.

        <EditText 
            android:inputType="text"
            android:maxLines="1"
            android:imeOptions="actionNext" />
Herrah answered 1/12, 2016 at 8:54 Comment(0)
G
11

Finally i have got sure solution for this issue Just add these 3 lines in your edit text and it will be working fine

        android:maxLines="1"
        android:inputType="text"
        android:imeOptions="actionDone"

Here you can add maxLines according to your requirement. Do not use singleLine as it is deprecated now. Good luck!

Goblin answered 26/7, 2017 at 12:30 Comment(0)
S
10

These three lines are enough.

android:singleLine="true"
android:inputType="text"
android:imeOptions="actionNext"
Solid answered 22/1, 2020 at 5:27 Comment(1)
android:singleLine="true" has been deprecated since API Level 15 (developer.android.com/reference/android/R.attr.html#singleLine) Please use android:maxLines="1" instead.Tuft
N
8
android:inputType="text"

You have to specify an inputType in order for imeOptions to function.

Nightrider answered 26/5, 2017 at 16:19 Comment(1)
what if the last item is password in form?Yoga
S
7

below code is force

android:inputType="text"
Smelter answered 12/1, 2020 at 5:44 Comment(0)
U
6

Only this worked for me.

Change it:

android:maxLines="1"
android:inputType="text"
android:imeOptions="actionNext"

on that:

android:singleLine="true"
android:inputType="text"
android:imeOptions="actionNext"
Uranometry answered 21/11, 2018 at 9:19 Comment(1)
inputType="text" did it for me.Infundibuliform
T
5

Key here is to set input type and imeOptions attributes

<EditText 
   android:inputType="number"
   android:maxLines="1"
   android:imeOptions="actionSearch" />
Tomahawk answered 13/1, 2017 at 10:55 Comment(0)
B
5

Only put in your EditText xml

android:inputType="text"
Bhatt answered 23/9, 2021 at 6:39 Comment(0)
H
4
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/auth_register_re_password"
    android:hint="Enter Password Again"
    android:imeActionLabel="login"
    android:gravity="center"
    android:imeOptions="actionUnspecified"
    android:inputType="textPassword"
    android:maxLines="1"/>
Heliotaxis answered 14/12, 2016 at 5:33 Comment(1)
what does actionUnspecified do exactly.Pforzheim
A
0

Add this following lines to in your EditText.

<Edittext
android:layout_height = "match_parent"
android:layout_widht = "match_parent"
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionSearch"
android:imeActionLabel="Search"
android:hint = "Search Here" />
Autoerotic answered 13/6, 2022 at 5:9 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Ephah
U
0

Observation that i saw for this: When you call implicit keyboard for a particular input, the android checks whether keyboard was called for same input box previously or not.

If called for same input box just show the previous ime option for that input box or else check the ime option that is currently set and use it.

There is some kind of caching which is creating the problem.

Unsubstantial answered 22/3, 2023 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.