【问题标题】:aoutofocus to the next edit text field自动对焦到下一个编辑文本字段
【发布时间】:2012-10-25 08:51:55
【问题描述】:

我正在使用编辑文本视图,并希望在达到最大长度时自动移动到下一个文本字段 就像在 xml 如何移动到下一个文本字段 来自 xml 或来自代码 任何帮助/建议都将受到欢迎 乌斯曼库尔德

【问题讨论】:

    标签: android android-edittext


    【解决方案1】:

    将 TextWatcher 与您的编辑文本一起使用,当您的编辑文本超过最大限制时,您可以请求将焦点放在您的文本框上。

    EditText edit= (EditText) findViewById (R.id.myedit);
    
     edit.addTextChangedListener(new TextWatcher() 
     {
       public void onTextChanged(CharSequence s, int start, int before, int count) 
        { 
          if (s.length() >= EDIT_MAX_LEN) 
           { 
               text.requestFocus(); 
           }
         }
        @Override
        public void afterTextChanged(Editable arg0) {
        }
    
        @Override
        public void beforeTextChanged(CharSequence s, int start,
                int count, int after) {
        }
    });
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-01-06
      • 2014-12-26
      • 1970-01-01
      • 2011-09-11
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      相关资源
      最近更新 更多