xml 中的 fragment
<fragment
android:id="@+id/parent_fragment"
android:name="com.app.example.ParentFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
在 Activity 中绑定(bind)
@BindView(R.id.parent_fragment)
ParentFragment parentFragment;
gradle 构建错误信息
@BindView fields must extend from View or be an interface
是否有类似@BindFragment
的东西用于使用@+id
绑定(bind)XML fragment ?
如果这是显而易见的事情,我很抱歉。
显然,那个库中没有这样的注释。
http://jakewharton.github.io/butterknife/
由于您的 Activity 中不会有很多 fragment ,因此可能没有必要使用库。只需使用 FragmentManager
的经典方法
parentFragment = (ParentFragment) getSupportFragmentManager().findFragmentById(R.id.parent_fragment);
我是一名优秀的程序员,十分优秀!