Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android edittext key return goes to next text

I have a series of EditText entries and would like it so when the user hits the enter key it will go to the next Editext. I know how do this one at a time but is there a way to tell all of the edittext controls to use the same function that checks the key entry and advances the cursor. It seems kind of crazy to have one function for each of the EditTexts

like image 527
Mark Worsnop Avatar asked Feb 15 '11 01:02

Mark Worsnop


3 Answers

Much simpler than sniffing keys: try setting android:singleLine="true" and android:imeOptions="actionNext" (at least for single-line entry textviews). Read more in the Android documentation for TextView.

Update: singleLine is deprecated now, but you can leave it out. It's the default behavior for editable text as long as you don't explicitly set android:inputType="textMultiLine", and inputType overrides the suggested singleLine replacement of maxLines="1" for editable text anyways.

like image 94
Yoni Samlan Avatar answered Nov 01 '22 11:11

Yoni Samlan


For an alternative or a newer approach for the answer given from Yoni...

Since singleLine is considereded deprecated, we can set manually to android:maxLines="1" with android:inputType="text".

Small explanation:

  • We use android:inputType="text" to specifically treat the input as plain text.
  • And we use android:maxLines="1" to set the max lines of the text to 1 (as it suggests).

Using maxLines="1" alone, will not cause any effect, but inputType="text" alone may work also, as Adam mentions (though I haven't checked this).

like image 8
edmundo096 Avatar answered Nov 01 '22 11:11

edmundo096


Adding

    android:inputType="text"

in XML is just enough. When You are not defining input type, then it goes to next line.

like image 5
Adam Staszak Avatar answered Nov 01 '22 12:11

Adam Staszak