Edittext jumps to next edittext after reaching the maximum edittext length

為{幸葍}努か 提交于 2019-12-19 07:00:12

问题


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


回答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);  
@Override
public void afterTextChanged(Editable s) {
    // TODO Auto-generated method stub

}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {
    // TODO Auto-generated method stub


}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    // TODO Auto-generated method stub
if(count==length){
edt2.requestFocus()
}
}



回答2:


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
}


来源:https://stackoverflow.com/questions/17801945/edittext-jumps-to-next-edittext-after-reaching-the-maximum-edittext-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!