I have a editText in my app and i want to run some code when the user use (space) into it.So, please give me a little bit of idea on how to do that.
You don't need KeyListener
. Use TextWatcher for it:
((EditText)findViewById(R.id.your_edit_text)).addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(s != null && s.length() > 0 && s.charAt(s.length() - 1) == ' '){
//dp something
}
}
});
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