Egek92 Egek92 - 2 months ago 11
Android Question

@OnClick on Butterknife doesn't work

There is no error in code or gradle build but when I click to button, nothing happens

@BindView(R.id.bWakeup) Button bWakeup;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);


}

@OnClick(R.id.bWakeup)
public void wakeButtonClick(View v) {
Intent intent = new Intent(MainActivity.this, SetTimeActivity.class);
intent.putExtra(MODE, WAKEUP);
startActivity(intent);
}

Answer

I Followed below steps and its working fine for me.

Configure your project-level build.gradle to include the 'android-apt' plugin:

buildscript {
   repositories {
      mavenCentral()
   }
   dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
   }
}

apply the 'android-apt' plugin in your module-level build.gradle and add the Butter Knife dependencies:

Apply plugin: 'android-apt'

android {
  ...
}

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