Last active
August 29, 2015 13:57
-
-
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
This file contains hidden or 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; | |
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