OnClick() 事件和 OnClickListener 的区别? [英] Difference between OnClick() event and OnClickListener?

查看:20
本文介绍了OnClick() 事件和 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(View) 方法.如果你有一个打算监听点击的类,你应该既实现接口(如果还没有扩展一个这样做的类),也实现这个方法.您必须同时使用两者;它们不是某种替代品.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆