【问题标题】:android- how to implement text watcher, exampleandroid-如何实现文本观察器,示例
【发布时间】:2012-03-14 05:35:03
【问题描述】:

我有一个程序,其中我有多个 editText 和一个最终 editText.... 我想实现 TextWatcher 以反映整个 edittext 中的变化.. 但我不知道如何为多个编辑文本。

public void afterTextChanged(Editable s) {
    // TODO Auto-generated method stub
}

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

public void onTextChanged(CharSequence s, int start, int before, int count) {               
    total+=new Integer(s.toString());
    _EDTotal.setText(""+total);
}

在上面的例子中我会遇到一个问题......当我第一次输入值时,我会在 _EDTotal 中设置正确的值,但是如果我使用监听器在 editText 中删除(使用 backSpace)我不会可以用新的prob替换它。

【问题讨论】:

  • hmm...你能发布更多更清晰的代码吗..

标签: android listener textwatcher


【解决方案1】:

试试这样:

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) {
       //your action
   }
});

【讨论】:

    猜你喜欢
    • 2012-01-31
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 2010-09-06
    • 2020-05-18
    • 2022-01-01
    相关资源
    最近更新 更多