EDIT TEXT - ANDROID

Asked

Viewed 107 times

1

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

  • Basically as Carlos Rafael answered, but need to search the limit of editText to compare using the lentgh().

  • https://stackoverflow.com/questions/8069015/how-to-get-edittext-maxlength-setting-in-code

1 answer

0


You can use a Textwatcher, as the user type you will check the size 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: https://stackoverflow.com/questions/11134144/android-edittext-onchange-listener

Browser other questions tagged

You are not signed in. Login or sign up in order to post.