Skip to content

Instantly share code, notes, and snippets.

@KANGOD
Created August 19, 2016 03:05
Show Gist options
  • Save KANGOD/c0ba3ca599aee6d233061ee739d4ce89 to your computer and use it in GitHub Desktop.
Save KANGOD/c0ba3ca599aee6d233061ee739d4ce89 to your computer and use it in GitHub Desktop.
import android.text.Editable;
import android.text.TextWatcher;
/**
* Listen to "EmptyChange" events on an EditText.
* <p/>
* Created by KANGOD on 8/18/2016.
*/
public abstract class EditTextOnEmptyChangedListener implements TextWatcher {
@Override
public final void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public final void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() == 0) {
onEmptyChanged(true);
} else if (start == 0 && before == 0 && s.length() == count) {
onEmptyChanged(false);
} // else: not an "EmptyChange" event
}
@Override
public final void afterTextChanged(Editable editable) {}
/**
* @param isEmpty If the EditText is empty after text changed.
*/
public abstract void onEmptyChanged(boolean isEmpty);
}
etAuthCode.addTextChangedListener(new EditTextOnEmptyChangedListener() {
@Override
public void onEmptyChanged(boolean isEmpty) {
btnNextStep.setEnabled(!isEmpty);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment