Skip to content

Commit 9d402bb

Browse files
authored
Merge pull request #88 from FrankDomburg/onlychangeonedit
Changed so that SimpleTextWatcher does not get triggered when the edittext is not changed
2 parents a5561b1 + 684afdb commit 9d402bb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

textfieldboxes/src/main/java/studio/carbonylgroup/textfieldboxes/TextFieldBoxes.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ public void onFocusChange(View view, boolean b) {
433433
});
434434

435435
this.editText.addTextChangedListener(new TextWatcher() {
436+
437+
private String lastValue = "";
438+
436439
@Override
437440
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
438441
//do nothing
@@ -452,9 +455,16 @@ public void afterTextChanged(Editable editable) {
452455
} else {
453456
validate(); //this will call updateCounterText(true);
454457
}
455-
if (textChangeListener != null) {
456-
textChangeListener.onTextChanged(editable.toString(), onError);
458+
459+
// Only trigger simple watcher when the String actually changed
460+
461+
if (!lastValue.equals(editable.toString())){
462+
lastValue = editable.toString();
463+
if (textChangeListener != null) {
464+
textChangeListener.onTextChanged(editable.toString(), onError);
465+
}
457466
}
467+
458468
}
459469
});
460470

0 commit comments

Comments
 (0)