binding - ButterKnife Android: Unable to add Listener to View -


i added butter knife library gradle this:

dependencies {    compile 'com.jakewharton:butterknife:8.0.1'    ... } 

created button id btnpress. in activity, when tried add method @onclick(r.id.btnpress), on running application, method not execute.

activity:

public class mainactivity extends appcompatactivity {      @bindview(r.id.btnpress)     button btnpress;      @override     protected void oncreate(bundle savedinstancestate) {         ...         butterknife.bind(mainactivity.this);     }      //this method not being called when button pressed.     @onclick(r.id.btnpress)     void onpress() {         ...     } } 

here's how resolved issue:

first, in top-level build.gradle file, include:

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 

in buildscript dependencies, such as:

  buildscript {     dependencies {       classpath 'com.android.tools.build:gradle:2.0.0'       classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'     }   } 

then, in module's build.gradle file, include apply plugin: 'com.neenbedankt.android-apt' towards top.

now include butterknife library , compiler in module level build.gradle:

dependencies {     compile 'com.jakewharton:butterknife:8.0.1'     apt 'com.jakewharton:butterknife-compiler:8.0.1'     ... } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -