@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
ButterKnife.inject(this, view);
orButterKnife.inject(this);
? – Lapidaryactivity
orfragment
?, if you call from activitythis
is enough but if you are in fragment or adapter you must pass yourview
too – Lapidary