How can I detect when I press the return button on the on-screen keyboard which creates a newline in the EditText field.
I don't really care if I have to check for newline characters or the return key, but I want to send a message by pressing the return key on the keyboard.
I already tried a few different things, but I can't seem to get it working.
My EditText object is called chatInputET
if you want to know.
add listener to your input:
chatInputET.addTextChangedListener( new TextWatcher(){
@Override
public void onTextChanged( CharSequence txt, int start, int before, int count ) {
if( -1 != txt.toString().indexOf("\n") ){
doSendMsg();
}
}
} );
chatInputET.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String string = s.toString();
if (string.length() > 0 && string.charAt(string.length() - 1) == '\n') {
// do stuff
}
}
});
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