首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自复合控件的onTextChanged

来自复合控件的onTextChanged
EN

Stack Overflow用户
提问于 2018-09-20 20:11:44
回答 2查看 58关注 0票数 1

我想让使用EditLine的活动使用EditLineonTextChanged事件。这有可能吗?

EN

回答 2

Stack Overflow用户

发布于 2018-09-20 20:16:18

您需要在编辑文本上使用文本观察器来捕获任何编辑文本事件

代码语言:javascript
复制
editText.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void afterTextChanged(Editable s) {
      if(s.toString().equals("yes")){
      // your code here
          
        }
    }
});
票数 0
EN

Stack Overflow用户

发布于 2018-09-20 20:21:46

您可以将TextWatcher添加到EditText,并在TextWatcheronTextChanged(CharSequence s, int start, int before, int count)方法中处理所有文本更改。

示例:

代码语言:javascript
复制
EditText myEditText = findViewById(R.id.my_edit_text);
TextWatcher myTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
        //do validation on input here
        //for example
         if(s.toString().equalsIgnoreCase("yes")){
                //then perform some action. 
                // Make your button enable for example
            }
    };
myEditText.addTextChangedListener(myTextWatcher);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52424906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档