示例:我有一個EditText和1個按鈕(onclick:示例)。我想檢查在EditText中輸入的第一個單詞。Android:如何檢查EditText中的字符串?
public void example (View v) {
if (edittext.getText().toString() .... //How to check the first word that typed in edittext,
ex: if the first word typed in edittext equalsIgnoreCase("a")){
//Action
}
而不是按鈕單擊您可以使用TextWatcher。 – SilentKiller
此問題已被詢問。你可以在這裏查看:http://stackoverflow.com/questions/5067942/what-is-the-best-way-to-extract-the-first-word-from-a-string-in-java –
你必須使用onTextChanged事件http://stackoverflow.com/a/6003815/1584654 – GVillani82