Warm tip: This article is reproduced from serverfault.com, please click

EditText and Focus in Android Studio

发布于 2020-12-14 17:15:58

I need to insert a focus shift from one editText to another editText after a certain logic in my application. example: in a credit card number editText have a listener when the length of the value reaches 16 it skips to the expiration month editText ...

My code:

 numberCard.addTextChangedListener(new TextWatcher() {
        @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(s.length()==16){
              
              //  how to make it jump to another editText?
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
Questioner
Fernando Amaral
Viewed
0
akhil nair 2020-12-15 01:30:40

If your second EditText is editText2 the you could do ediText2.requestFocus()