如何删除monodroid中编辑文本的TextChangedListener

时间:2015-09-23 11:23:25

标签: c# android xamarin xamarin.android

我使用AddTextChangedListener编辑了文字:

edit_text.AddTextChangedListener(new NumberTextWatcher());

现在我要删除TextChangedListener for the EditText`。

我尝试过使用下面的代码,但我没有运气。

edit_text.RemoveTextChangedListener(NumberTextWatcher);

1 个答案:

答案 0 :(得分:1)

您需要将引用存储到某个地方NumberTextWatcher以便稍后将其删除

//Field that stores the reference
private readonly NumberTextWatcher watcher = new NumberTextWatcher();

//Adds the listener
edit_text.AddTextChangedListener(watcher);

//Later in your code you can simply remove it like this:
edit_text.RemoveTextChangedListener(watcher);