问题描述
是什么添加监听和设置收听者之间的差别。
What is the difference between adding a listener and setting a listener.
例如
addTextChangedListener(textWatcher);
setOnClickListener(clickListener);
答:
aioobe的回答后,我已经在我的项目测试了这个。
因此,我们可以做到这一点。
After aioobe's answer i have tested this in my project.So we can do this.
editText.addTextChangedListener(textWatcher1);
editText.addTextChangedListener(textWatcher2);
但我们不能做到这一点。(它会设置只有最后听众在这种情况下clickListener2)
but we can't do this.(It will set only the last listener in this case clickListener2)
button.setOnClickListener(clickListener1);
button.setOnClickListener(clickListener2);
另一个疑问
我不能够去思考,我需要两个textWatcher单EDITTEXT任何用例。任何人都可以给这样一个用例。 (我应该问这个问题作为单独问题吗?)
I am not able to think any use case in which i need two textWatcher for single editText. Can anybody give such a use case. (should i ask this question as separate question?)
推荐答案
如果你有一个设置
-method有通常只有一个监听器。 (我个人preFER称他们为处理程序,虽然)。
If you have a set
-method there's usually only one listener. (Personally I prefer to call them "handlers" though).
使用添加
- 方法您通常可以监听任意数量。
With add
-methods you can typically have an arbitrary number of listeners.
这篇关于添加监听器VS集监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!