2017-09-26 15 views
0

EditText에 일부 TextWatchers를 추가하려고하지만 필요한 경우 모두 제거해야합니다.EditText에서 모든 TextWatchers 제거

... 

@BindView(R.id.widget_search_edittext) 
MaterialEditText mEditText; 

private List<TextWatcher> textWatcherList; 

... 

public void addTextChangedListener(TextWatcher watcher) { 
    textWatcherList.add(watcher); 
    mEditText.addTextChangedListener(watcher); 
} 

public void removeAllTextChangedListeners() { 
    for (TextWatcher watcher : textWatcherList) { 
     mEditText.removeTextChangedListener(watcher); 
    } 
    textWatcherList.clear(); 
}  

하지만 그게 효과가 없습니까?

답변

1

확장 TextWather 클래스에서 equals()을 재정의해야합니다. arrayList abd에 저장된 감시자가 equals 함수에 의존하는 arraylist.indexOf(watcher)을 호출하여 제거 되었기 때문에. 나는 감시자을 제거하려고하면 감시자 내부적으로

+0

를 제거 텍스트 뷰 방법

public void addTextChangedListener(TextWatcher watcher) { if (mListeners == null) { mListeners = new ArrayList<TextWatcher>(); } mListeners.add(watcher); } /** * Removes the specified TextWatcher from the list of those whose * methods are called * whenever this TextView's text changes. */ public void removeTextChangedListener(TextWatcher watcher) { if (mListeners != null) { int i = mListeners.indexOf(watcher); if (i >= 0) { mListeners.remove(i); } } } 

모습은 그 –

+1

당신의 코드를 게시 호출되지 않습니다 일치 한 해주십시오 –

+0

난 그냥 테스트 거기에 브레이크 포인트를 넣어 tryied. 그러나 디버거는 결코 그것을 도달하지 못합니다. @Override public boolean equals (Object obj) { if (obj instanceof MyMaskWatcher) { true를 반환합니다. } else { false를 반환합니다. } } –