gpt4 book ai didi

android - 如何在 ButterKnife 中绑定(bind) XML fragment ?

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:22 25 4
gpt4 key购买 nike

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);

关于android - 如何在 ButterKnife 中绑定(bind) XML fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47050414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com