Skip to content

Instantly share code, notes, and snippets.

@shivanshuraj
Created December 30, 2022 17:50
Show Gist options
  • Save shivanshuraj/a74b0760d0c0d8397740c0cb12a5cc5b to your computer and use it in GitHub Desktop.
Save shivanshuraj/a74b0760d0c0d8397740c0cb12a5cc5b to your computer and use it in GitHub Desktop.
Bohanee: Move to next edittext

NOTE: PLEASE CALL THESE METHOD IN onCreate() METHOD AFTER referenceVariables() METHOD.

    cursorMovingFunction(OTP1, OTP2);
    cursorMovingFunction(OTP2, OTP3);
    cursorMovingFunction(OTP3, OTP4);
    cursorMovingFunction(OTP4, OTP5);
    cursorMovingFunction(OTP5, OTP6);

/** * method that moves cursor to next edittext after entering a number. * @param currentEditText-- the edittext on which number is entered. * @param nextEditText-- the edittext on which cursor has to move. */

private void cursorMovingFunction(EditText currentEditText, EditText nextEditText){
    currentEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (currentEditText.getText().toString().trim().length() ==1) {
                currentEditText.clearFocus();
                nextEditText.requestFocus();
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment