ButterKnife @OnClick annotation not working in Kotlin fragment
If you are using Kotlin, replace annotationProcessor
with kapt
The reason behind it is that may be you are using dependencies like this :
dependencies {
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}
replace it like this:
dependencies {
implementation 'com.jakewharton:butterknife:10.1.0'
kapt'com.jakewharton:butterknife-compiler:10.1.0'
}
Why don't you do it like this?
// get reference to button
val btn_click_me = findViewById(R.id.btn_click_me) as Button
// set on-click listener
btn_click_me.setOnClickListener {
// your code to perform when the user clicks on the button
Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()
}