我有一個編輯文本,我只是想通過鍵盤插入英文字符或單詞時顯示一條消息,我該怎麼辦?droid:我如何驗證EditText輸入?
0
A
回答
0
只是做這樣的 -
((EditText)findViewById(R.id.et_testo)).addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
Toast.makeToast(activity.this, s.toString(), Toast.Long).show();
}
});
看一看TextWatcher
1
0
使用TextWatcher看在的EditText文字和無論何時檢測到英文字母或者單詞「onTextChanged」 TextWatcher的mehod可以顯示一個消息。
一個例子是如下
TextWatcher textWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// or here
}
public void afterTextChanged(Editable s) {
// Check for English Character or word here and show message
};
// Set listener on the original text field
itemText.addTextChangedListener(textWatcher);
}
希望它能幫助!
+0
謝謝,你的代碼很有幫助。 – anonymous
+0
@malina然後upvote並接受答案:) –
相關問題
- 1. 驗證EditText輸入
- 2. 如何驗證EditText
- 3. 如何驗證EditText?
- 4. AlertDialog EditText輸入驗證不起作用
- 5. 我如何輸入驗證PHP
- 6. 如何驗證在edittext中輸入的號碼? - 機器人
- 7. 如何驗證textField輸入?
- 8. 如何驗證DataGridView輸入?
- 9. 輸入驗證,我如何輸入獨特的名稱
- 10. 的EditText驗證
- 11. 驗證EditText
- 12. 驗證輸入
- 13. 驗證輸入
- 14. 輸入驗證
- 15. 驗證輸入
- 16. 如何驗證edittext-mask以及如何驗證AutoCompleteTextview?
- 17. 如何在Android中使用自定義正則表達式驗證EditText輸入?
- 18. 如何驗證從EditText上電子郵件和密碼輸入註冊用戶
- 19. 驗證EditText輸入並更新用戶分數
- 20. 驗證的EditText是空的,並等待用戶輸入數據
- 21. 驗證的EditText含量只要用戶輸入數據
- 22. 兩個EDITTEXT驗證
- 23. PHP輸入驗證
- 24. jQuery驗證輸入
- 25. 輸入驗證Silverlight
- 26. C++輸入驗證
- 27. cin.peek輸入驗證
- 28. Javascript輸入驗證
- 29. Settings.bundle,輸入驗證
- 30. JOptionPane輸入驗證
使用TextWatcher(http://developer.android.com/reference/android/text/TextWatcher.html)和驗證都(http://blog.donnfelker.com/2011/11/23/android-validation-with-edittext/)。 –
http://stackoverflow.com/questions/7432083/how-to-use-edittext-ontextchanged-event-when-i-press-the-number – Bush