Edittext, Onkeylistener Or Textwatcher (barcode Scanning)
I'm using a barcode scanner which inserts barcode string into an EditText in this format '12345\n'. Instead of using a search button, I want to trigger the search event by the '\n'
Solution 1:
If you clear the EditText
content in the afterTextChanged()
, you shouldn't have an infinite loop.
@Override
public void afterTextChanged(Editable s) {
if (s.length > 0) {
char lastCharacter = s.charAt(s.length() - 1);
if (lastCharacter == '\n') {
String barcode = s.subSequence(0, s.length() - 1).toString();
myEditText.setString("");
searchBarcode(barcode);
}
}
Post a Comment for "Edittext, Onkeylistener Or Textwatcher (barcode Scanning)"