Skip to content

Instantly share code, notes, and snippets.

@dominicthomas
Created December 22, 2014 11:19
Show Gist options
  • Save dominicthomas/eb9d9597b0ee8e993ac7 to your computer and use it in GitHub Desktop.
Save dominicthomas/eb9d9597b0ee8e993ac7 to your computer and use it in GitHub Desktop.
Check that the last key entered was enter... and replace with blank character. This can be used in an android TextWatcher, and called in afterTextChanged to stop a user pressing enter or handle the case that someone does. This was implemented in an attempt to limit the amount of enters someone could press when entering text in a multiline editex…
private void checkLastKeyWasEnter(final Editable pSequence) {
if (pSequence.length() > 0 && pSequence.charAt(pSequence.length() - 1) == '\n') {
pSequence.replace(pSequence.length() - 1, pSequence.length(), "");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment