@OnClick
is not working in implementation of ButterKnife Library
When I click on the Button
, nothing is happening.
This is my full code:
public class MainActivity extends ActionBarActivity {
@InjectView(R.id.edit_user)
EditText username;
@InjectView(R.id.edit_pass)
EditText password;
@OnClick(R.id.btn)
void submit() {
// TODO call server...
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
// TODO Use "injected" views...
}
}
This is my xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/edit_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="user" />
<EditText
android:id="@+id/edit_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="user" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
Thanks
For anyone running into this issue in Android Studio, make sure you are including both of the necessary dependencies and the apt plugin in your respective build files (check the Butterknife readme). I rushed through the docs and only included the compile dependency, which caused binding to fail silently.