的OnClick()事件和OnClickListener之间的区别? [英] Difference between OnClick() event and OnClickListener?
问题描述
我总是在我的大部分项目中使用的onclick()
事件。但是,我读 OnClickListener()
。谁能告诉什么是这两者之间的区别是什么?哪一个是最好的Android应用程序中使用?
I'm always using onclick()
event in most of my projects. But, I read about OnClickListener()
. Can anyone tell what's the difference between these two? And which one is best to use in Android application?.
推荐答案
我不知道这个问题是显而易见的。 View.OnClickListener
是一个接口,它定义了的onClick(视图)
方法。如果你有一个类,它打算监听点击,你都应该实现的接口(如果尚未扩展一个类,做),并实施这种方法了。你必须同时使用;他们不是在某种程度上替代品。
I'm not sure the question is clear. View.OnClickListener
is an interface, which defines the onClick(View)
method. If you have a class which intends to listen for clicks, you should both implement the interface (if not already extending a class that does), and implement this method too. You have to use both; they're not somehow alternatives.
这篇关于的OnClick()事件和OnClickListener之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!