0

I want to move back from second edit text to first after I press back and how can it be done using the addtextchangelisterner

  • You can override the `onBackPressed()` method, check if the text box is empty, if empty just call `super.onBackPressed()`. – Sam Chen Apr 11 '22 at 18:53
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 12 '22 at 01:36

1 Answers1

0

You can find the answer over here This is an example:

StringBuilder sb=new StringBuilder();

         edtPasscode1.addTextChangedListener(new TextWatcher() {
             public void onTextChanged(CharSequence s, int start, int before, int count) {
                 // TODO Auto-generated method stub
                 if(sb.length()==0&edtPasscode1.length()==1)
                 {
                     sb.append(s);
                     edtPasscode1.clearFocus();
                     edtPasscode2.requestFocus();
                     edtPasscode2.setCursorVisible(true);

                 }
             }

             public void beforeTextChanged(CharSequence s, int start, int count,
                     int after) {

                 if(sb.length()==1)
                 {

                     sb.deleteCharAt(0);

                 }

             }

             public void afterTextChanged(Editable s) {
                 if(sb.length()==0)
                 {

                     edtPasscode1.requestFocus();
                 }

             }
         });