How do i make some code run when exactly 4 digits/letters have been entered in a edit开发者_StackOverflowtext?
All you would need to do is add a TextWatcher to your edittext.
myEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(messageText.getText().length() == 4){
//call a function here
}
}
@Override
public void afterTextChanged(Editable s) {}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
});
精彩评论