Created
October 9, 2019 23:19
-
-
Save Shujito/13fe5999fc90863a8af97a5f20ff453c to your computer and use it in GitHub Desktop.
Utilidad para usar TextWatcher como lambda en TextView::addTextChangedListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextView textView = new TextView(this); | |
textView.addTextChangedListener(new TextWatcherAdapter() { | |
@Override | |
public void action(Action action, CharSequence charOrEditable, int start, int count, int afterOrBefore) { | |
if (action == Action.afterTextChanged) { | |
// magia verde | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextView textView = new TextView(this); | |
textView.addTextChangedListener((TextWatcherAdapter) (action, charOrEditable, start, count, afterOrBefore) -> { | |
if (action == TextWatcherAdapter.Action.afterTextChanged) { | |
// magia verde | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface TextWatcherAdapter extends TextWatcher { | |
enum Action { | |
beforeTextChanged, | |
onTextChanged, | |
afterTextChanged | |
} | |
default void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
this.action(Action.beforeTextChanged, s, start, count, after); | |
} | |
default void onTextChanged(CharSequence s, int start, int before, int count) { | |
this.action(Action.onTextChanged, s, start, count, before); | |
} | |
default void afterTextChanged(Editable editable) { | |
this.action(Action.afterTextChanged, editable, 0, 0, 0); | |
} | |
void action(Action action, CharSequence charOrEditable, int start, int count, int afterOrBefore); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment