Skip to content Skip to sidebar Skip to footer

Android Edittext Question, Replace Keypad Enter With Done

I'm defining an edit text like so...

Solution 1:

Simple solution: add android:singleLine="true" for the EditText. This will replace the enter with Next (for all edittexts except the last one) and Done (for the last one).

Solution 2:

Just add in the EditText XML : android:imeOptions="actionDone"

Solution 3:

android:imeOptions="actionNext"

It replaces the name of the enter key with "Next" in the virtual keyboard and by clicking on it - focus jumps to the next field

In your layout, you would do things like this

<EditText...android:text="Field 1"android:imeOptions="actionNext" /><EditText...android:text="Field 2"android:imeOptions="actionNext" />

And in Java

TextViewfield2= (TextView) field1.focusSearch(View.FOCUS_RIGHT);
field2.requestFocus();

It's up to you to decide which field will request focus next.

Solution 4:

Here is an updated answer:

android:maxLines="1"

The accepted answer of android:singleLine="true" has been deprecated.

Solution 5:

About your other question, getting the text to auto-erase, you should include it in android:hint instead of android:text.

Post a Comment for "Android Edittext Question, Replace Keypad Enter With Done"