問題描述
我有一系列 EditText 條目并且想要它,因此當用戶按下回車鍵時,它將轉(zhuǎn)到下一個 EditText.我知道如何一次執(zhí)行此操作,但是有沒有辦法告訴所有的 edittext 控件使用檢查鍵輸入和前進光標的相同功能.為每個 EditText 設置一個函數(shù)似乎有點瘋狂
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
推薦答案
比嗅探鍵簡單得多:嘗試設置 android:singleLine="true"
和 android:imeOptions="actionNext"
(至少對于單行輸入文本視圖).閱讀有關 TextView 的 Android 文檔 中的更多信息.
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.
更新: singleLine
已棄用 現(xiàn)在,但您可以忽略它.這是可編輯文本的默認行為,只要您沒有明確設置 android:inputType="textMultiLine"
,并且 inputType
會覆蓋建議的 singleLine
無論如何替換 maxLines="1"
為可編輯文本.
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.
這篇關于Android edittext 鍵返回到下一個文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!