Utilidad para usar TextWatcher como lambda en TextView::addTextChangedListener
|
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 |
|
} |
|
} |
|
}); |
|
TextView textView = new TextView(this); |
|
textView.addTextChangedListener((TextWatcherAdapter) (action, charOrEditable, start, count, afterOrBefore) -> { |
|
if (action == TextWatcherAdapter.Action.afterTextChanged) { |
|
// magia verde |
|
} |
|
}); |
|
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); |
|
} |