Skip to content

Instantly share code, notes, and snippets.

@arriolac
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriolac/9636241 to your computer and use it in GitHub Desktop.
Save arriolac/9636241 to your computer and use it in GitHub Desktop.
TextWatcher that will proceed to the next focusable view once the specified length has been reached
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
/**
* Created by chris on 3/13/14.
*/
public class AutoNextTextWatcher implements TextWatcher {
private EditText mEditText;
private int mMaxLength;
public AutoNextTextWatcher(EditText editText, int maxLength) {
mEditText = editText;
mMaxLength = maxLength;
editText.addTextChangedListener(this);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mEditText.getText().length() >= mMaxLength) {
final View nextView = mEditText.focusSearch(View.FOCUS_DOWN);
if (nextView != null) {
nextView.requestFocus();
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment