I have an edittext , I just want to show a message when an english character or word is inserted via the keyboard , what shall I do?
Asked
Active
Viewed 730 times
0
-
Use TextWatcher (http://developer.android.com/reference/android/text/TextWatcher.html) and Validation both (http://blog.donnfelker.com/2011/11/23/android-validation-with-edittext/). – Ogulcan Orhan Oct 04 '12 at 06:24
-
http://stackoverflow.com/questions/7432083/how-to-use-edittext-ontextchanged-event-when-i-press-the-number – Bush Oct 04 '12 at 06:25
3 Answers
0
Use TextWatcher to watch the text in the EditText and whenever an English character or word is detected in "onTextChanged" mehod of TextWatcher you can show a message.
An Example is as follows
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);
}
Hope it helps!!!

Rajeev N B
- 1,365
- 2
- 12
- 24
0
Just do like this -
((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();
}
});
Have a look at TextWatcher

Praveenkumar
- 24,084
- 23
- 95
- 173