java - 在android中实现关键字

标签 java android

在 Android 中我看到这样的代码:

public class Now extends Activity implements View.OnClickListener

这在java中合法吗? View.OnClickListener 在这里到底代表什么。

最佳答案

问题似乎与View.x 的使用有关。正如@Vicente_Plata 在评论中很好地指出的那样:

OnClickListener is an interface declared inside the View class. Like an "inner class" but, rather, an "inner interface


旧答案:
View.OnclickListener 是一个接口(interface)。它定义了您的 Activity 必须实现的方法,在本例中为 OnClickListener()。任何检查的人都想知道您的类中是否有这样的函数,因此他们可以将 Now 用作 OnclickListener

接口(interface)不提供实现。

此外,来自 this page

Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.

关于java - 在android中实现关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5769036/

相关文章:

android - 不同屏幕尺寸的不同字符串

java - java中大数的模数

java - 如何在 netbeans 中为 JPanel 设置背景图片?

android - 如何将 Gradle 与 Apache Cordova 同步

android - Android 中有效的谷歌帐户 OAuth 2 token

android - 在设备锁定/解锁后保持 fragment UI 状态

android - 将 1 个事件放在地板上

Java 正则表达式、匹配模式、词对

java - 如何在 PHP 中解码 Java 流

Java 1.6 夏令时