Reputation: 4388
I am trying to use Butterknife in Android, it does not seem to work. could you guide me where I am doing it wrong.
I tried to place a debug point in inside 'OnClick', but does not seem to come there.
Gradle dependencies (app)
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
activity_main.xml
<LinearLayout
android:id="@+id/action_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/fragment_container"
android:weightSum="2">
<Button
android:id="@+id/btn_frg_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Fragment One"/>
<Button
android:id="@+id/btn_frg_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Frag Two"/>
</LinearLayout>
MainActivity.java
@OnClick({R.id.btn_frg_one, R.id.btn_frg_two})
public void addFrgToCon(View view){
switch (view.getId()){
case R.id.btn_frg_one:
addFragment(new FOne());
break;
case R.id.btn_frg_two:
addFragment(new FTwo());
break;
}
}
public void addFragment(Fragment fragment){
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
Upvotes: 1
Views: 224
Reputation: 57
> use ButterKnife.bind(this);
>
>
> Other provided binding APIs:
>
> Bind arbitrary objects using an activity as the view root. If you use a pattern like MVC you can bind the controller using its activity
> with ButterKnife.bind(this, activity).
>
> Bind a view's children into fields using ButterKnife.bind(this). If you use <merge> tags in a layout and inflate in a custom view
> constructor you can call this immediately after. Alternatively, custom
> view types inflated from XML can use it in the onFinishInflate()
> callback.
Upvotes: 0
Reputation: 9692
i think you forgot this
ButterKnife.bind(this);
for more information read Butternife
Upvotes: 2