我正在尝试在 Android 中使用 Butterknife,它似乎不起作用。你能指导我哪里做错了吗?
我试图在“OnClick”内部放置一个调试点,但似乎并没有到达那里。
Gradle 依赖项(应用程序)
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>
主要 Activity .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();
}
最佳答案
关于android - 在 Android 中使用 Butterknife,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47406892/