EDIT TEXT - ANDROID

1

I have 3 edit texts in my project, I set the maximum d characters for each one, I would like to know how to do it when it reaches the maximum it gives focus to another. Ex: the first one has at max 2, then I type 10 and it already gives focus to next edit text.

    
asked by anonymous 31.01.2018 / 05:23

1 answer

0

You can use a TextWatcher, as the user goes typing you go checking the length of the string, when you reach the length limit you change the focus to another edittext.

public class YourClass extends Activity {

 private EditText yourEditText;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        yourEditText = (EditText) findViewById(R.id.yourEditTextId);

        yourEditText.addTextChangedListener(new TextWatcher() {

          public void afterTextChanged(Editable s) {

            // you can call or do what you want with your EditText here
            SE tamanho = tamanhoLimite ENTAO
               muda o foco
            FIMSE

          }

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

          public void onTextChanged(CharSequence s, int start, int before, int count) {}
       });
    }

}

You can take a look at this other topic here, which is where I took the code snippet above: link

    
31.01.2018 / 11:47