问题描述
我认为标题是不言自明的. performClick()
和callOnClick()
方法之间的用法有何区别?看来它们的工作方式相同,那么为什么View
那么有两种方法呢?
I think the title is self-explanatory. What is the difference in usage between the performClick()
and callOnClick()
methods?It seems that they work the same way, so why does View
have two methods then?
推荐答案
这两种方法的Javadoc也很容易解释:
The Javadoc for both methods is pretty self-explanatory too:
public boolean performClick ()
调用此视图的OnClickListener(如果已定义). 执行全部 与点击相关的常规操作:报告可访问性 活动,播放声音等
Call this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.
public boolean callOnClick ()
直接调用任何附加的OnClickListener. 与performClick()不同, 这只会调用侦听器,并且不会进行任何关联的点击 诸如报告可访问性事件之类的操作.
Directly call any attached OnClickListener. Unlike performClick(), this only calls the listener, and does not do any associated clicking actions like reporting an accessibility event.
这篇关于Android ViewperformClick()和callOnClick()的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!