0

当我将 a 设置TextWatcherEditText这样时:

editText1.addTextChangedListener(watcher);

接口方法onTextChanged和被触发afterTextChangedbeforeTextChanged无论是否EditText包含文本。

我假设这些方法仅在绑定后的文本更改后调用。我可以防止这种行为吗?我是否犯了导致这种行为的逻辑错误?

谢谢

编辑:

setText()以前addTextChangedListener

调用栈:

DalvikVM[localhost:8600]    
Thread [<1> main] (Suspended)   
    <VM does not provide monitor information>   
    EditText(TextView).sendOnTextChanged(CharSequence, int, int, int) line: 7875    
    EditText(TextView).setText(CharSequence, TextView$BufferType, boolean, int) line: 3488  
    EditText(TextView).setText(CharSequence, TextView$BufferType) line: 3341    
    EditText.setText(CharSequence, TextView$BufferType) line: 90    
    EditText(TextView).setText(CharSequence) line: 3316 
    EditText(TextView).onRestoreInstanceState(Parcelable) line: 3216    
    EditText(View).dispatchRestoreInstanceState(SparseArray) line: 10079    
    ...
4

1 回答 1

2

当您调用addTextChangedListener(TextWatcher). 您可能只是setText()以编程方式调用或以其他方式修改文本。


这是源代码android.widget.TextView.addTextChangedListener

public void addTextChangedListener(TextWatcher watcher) {
    if (mListeners == null) {
        mListeners = new ArrayList<TextWatcher>();
    }
    mListeners.add(watcher);
}
于 2013-01-06T03:01:51.997 回答