Skip to content Skip to sidebar Skip to footer

Edittext Jumps To Next Edittext After Reaching The Maximum Edittext Length

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 this..

Solution 1:

On reachin the count you change the focus of the edittext to the next one

Edittext edt1;
Edittext edt2:
//mount the views to java from xml
edt1.addTextChangedListener(this);  
@OverridepublicvoidafterTextChanged(Editable s) {
    // TODO Auto-generated method stub

}
@OverridepublicvoidbeforeTextChanged(CharSequence s, int start, int count,
        int after) {
    // TODO Auto-generated method stub


}
@OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {
    // TODO Auto-generated method stubif(count==length){
edt2.requestFocus()
}
}

Solution 2:

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

EditText textBox1;
EditText textBox2;

textBox1.addTextChangedListener(this);

@OverridepublicvoidafterTextChanged(Editable s) {
   if (s.length() == MAX_LENGTH) {
      textBox2.requestFocus();
   }
}

@OverridepublicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) {
   // nil
}

@OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {
   // nil
}

Post a Comment for "Edittext Jumps To Next Edittext After Reaching The Maximum Edittext Length"