I was wondering what the best way to do a live character count of an edit-text box is in Android. I was looking at this but I couldn\'t seem to make any sense of it.
<
Clear way;
abstract class CharacterWatcher : TextWatcher {
override fun afterTextChanged(text: Editable?) {
afterCharacterChanged(text?.lastOrNull(), text?.length)
}
override fun beforeTextChanged(text: CharSequence?, start: Int, count: Int, before: Int) {}
override fun onTextChanged(text: CharSequence?, start: Int, before: Int, count: Int) {}
abstract fun afterCharacterChanged(char: Char?, count: Int?)
}
editText.addTextChangedListener(new CharacterWatcher() {
@Override
public void afterCharacterChanged(@Nullable Character character, @Nullable Integer count) {
action()
}
});