Focus next textview automatically

后端 未结 2 964
广开言路
广开言路 2021-01-02 14:39

I have a TextView with android:maxLength set to 3 and another with android:maxLength set to 7.

I wan

2条回答
  •  旧巷少年郎
    2021-01-02 15:17

    For future readers expecting to COPY/PASTE

    int MAX_LENGTH = 3;
    
    txt1.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() == MAX_LENGTH) {
                txt2.requestFocus(View.FOCUS_DOWN);
            }
        }
    
        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    

提交回复
热议问题