Created
August 19, 2016 03:05
-
-
Save KANGOD/c0ba3ca599aee6d233061ee739d4ce89 to your computer and use it in GitHub Desktop.
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
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); | |
} |
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
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