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
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.
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:
android:inputType="text"
to specifically treat the input as plain text.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).
Adding
android:inputType="text"
in XML is just enough. When You are not defining input type, then it goes to next line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With