![](/img/trans.png)
[英]How to use TextWatcher to automatically get values from edittext and multiply them?
[英]How to get the currently typed text from edittext using textwatcher?
例如:如果我輸入了“你好先生”,那么在我開始在 android 中使用textwatcher
輸入“先生”之前,我textwatcher
在點擊空格鍵后立即獲得“你好”。 一旦用戶點擊空格鍵,我需要當前從edittext
輸入單個文本, edittext
不是來自edittext
所有字符串。 任何人都可以使用textwatcher
提供可靠的想法嗎?
public void onTextChanged(CharSequence charsequence, int i, int j, int k) {
// TODO Auto-generated method stub
// I need only currently typed text not all the string from edittext
}
});
每當調用 onTextChanged 時,您都會獲得整個字符串,沒有“按下空格鍵時”回調,因此您必須自己編寫。
一個想法可能如下:
在 onTextChanged() 中,檢查字符串中是否有空格,如果找到,則遍歷字符串,將字符串拆分為空格分隔的字符串數組。
然后您將每個字符串都放在一個數組中,然后只需找到您需要的字符串。
這將使字符串“你今天過得怎么樣?” 進入“How”“are”“you”“doing”“today?”的數組,然后它是一個簡單的數組索引案例以找到您需要的字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.