Android: ButterKnife onclick is not working

Leo N
2 min readApr 2, 2020

--

https://jakewharton.github.io/butterknife/

Gradle

implementation("com.jakewharton:butterknife:10.2.1") {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-compat'
}
annotationProcessor "com.jakewharton:butterknife-compiler:10.2.1"

Situation

When click on these view, there is nothing happened

Solution

1. Make sure call: ButterKnife.bind

Butter Knife doesn’t participate in configuration changes in any way. After rotation onCreateView is called again, you call ButterKnife.bind, and it sets a click listener back to your method. Any failure to receive clicks is a disagreement between you and your view hierarchy or perhaps due to multiple fragments overlapping each other.

@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields...
}

2. Please check and remove those

Thanks:

--

--

Leo N
Leo N

Written by Leo N

🇻🇳 🇸🇬 🇲🇾 🇦🇺 🇹🇭 Engineer @ GXS Bank, Singapore | MSc 🎓 | Technical Writer . https://github.com/nphausg

No responses yet