Android ButterKnife

梦想的初衷 提交于 2019-12-02 09:37:05

You haven't included annotation processor for ButterKnife code generation. Do it like described on the GitHub page:

dependencies {
  compile 'com.jakewharton:butterknife:8.4.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

And apply the plugin:

apply plugin: 'com.jakewharton.butterknife'

Otherwise, your code looks fine.

Explanation: ButterKnife library uses annotation processor for generating the code that provides the references to views and executes ButterKnife annotated methods. If you rebuild your project, and the AndroidStudio shows that the @OnClick annotated method is unused, then somethings wrong. If the annotation processor is provided and works correctly, it should show as used and lead to a generated method.

Add this line:

annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

as well in your build.gradle.

See here for more info

Well, Butterknife is yesterday, use databinding instead: https://developer.android.com/topic/libraries/data-binding/index.html. This is almost the same tool out of the box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!