Search code examples
androidbutterknife

@OnClick is not working in implementation of ButterKnife Library


@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


Solution

  • As mentioned in the Butterknife docs, If you are using Eclipse, you will need to configure the IDE before the annotations will be processed