I have EditText view in android .. i want when the enters a letter the application get the letter ..
that mean the need to have a listener or event handler to get each letter is entered
hope my question is clear
EditText et = (EditText) findViewById(R.id.EditText01);
et.addTextChangedListener( new TextWatcher()
{
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
try
{
char currentChar = arg0.charAt(arg1); // currently typed character
}
catch(Exception e)
{
// error
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
You can use the method TextView.addTextChangedListener(TextWatcher watcher)
TextWatcher provides 3 nice methods :
public abstract void afterTextChanged (Editable s)
public abstract void beforeTextChanged (CharSequence s, int start, int count, int after)
public abstract void onTextChanged (CharSequence s, int start, int before, int count)
Here the doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With