Edittext jumps to next edittext after reaching the maximum edittext length

前端 未结 2 403
孤独总比滥情好
孤独总比滥情好 2021-01-12 08:53

In my layout I have 4 edittext.. I need to jump to the next edittext after reaching the maximum length . But there is a problem..How to do it?.. Please anybody help me to do

2条回答
  •  死守一世寂寞
    2021-01-12 09:23

    This approach works by inspecting the length of inputted text after the text field changes.

    EditText textBox1;
    EditText textBox2;
    
    textBox1.addTextChangedListener(this);
    
    @Override
    public void afterTextChanged(Editable s) {
       if (s.length() == MAX_LENGTH) {
          textBox2.requestFocus();
       }
    }
    
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
       // nil
    }
    
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
       // nil
    }
    

提交回复
热议问题