Ich versuche, Butterknife in Android zu verwenden, scheint es nicht zu funktionieren. Könntest du mir zeigen, wo ich falsch liege?Verwenden von Butterknife in Android
Ich habe versucht, einen Debug-Punkt in 'OnClick' zu platzieren, scheint aber nicht dorthin zu kommen.
Gradle Abhängigkeiten (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();
}
https://stackoverflow.com/questions/24126066/butterknife-fragment-button-not-working –