How to change the focus to next edit text in android?

后端 未结 9 1669
南笙
南笙 2020-12-03 01:03

\"enter

The User can enter only one digit in the edit text. if he enters the value in

9条回答
  •  -上瘾入骨i
    2020-12-03 01:30

    Try TextWatcher instead of onKeyListener

    B'coz if want to edit your password, in that case TextWatcher will give you more method to dealt with..

    Edited:-

    StringBuilder sb=new StringBuilder();
    
             edtPasscode1.addTextChangedListener(new TextWatcher() {
                 public void onTextChanged(CharSequence s, int start, int before, int count) {
                     // TODO Auto-generated method stub
                     if(sb.length()==0&edtPasscode1.length()==1)
                     {
                         sb.append(s);
                         edtPasscode1.clearFocus();
                         edtPasscode2.requestFocus();
                         edtPasscode2.setCursorVisible(true);
    
                     }
                 }
    
                 public void beforeTextChanged(CharSequence s, int start, int count,
                         int after) {
    
                     if(sb.length()==1)
                     {
    
                         sb.deleteCharAt(0);
    
                     }
    
                 }
    
                 public void afterTextChanged(Editable s) {
                     if(sb.length()==0)
                     {
    
                         edtPasscode1.requestFocus();
                     }
    
                 }
             });
    

    Hope this work.

提交回复
热议问题