android - Butterknife 将 View 绑定(bind)到不同的源

标签 android butterknife

在我的 Activity 中,我使用两种 View :X 型和 Y 型。

X 类型 View 直接在我调用的 xml 布局文件中定义 setContentView() .对于 Y 类型的 View ,它们出现在我在 Activity 中膨胀的对话框中,然后将其作为标题 View 添加到我的 ListView 中(在 Activity xml 中)。

现在,我如何使用 butterknife 来注入(inject)这两种 View 类型。如果我调用 Butterknife.bind(@NonNull Activity target) ,它只会注入(inject) Activity xml 中存在的那些 View 。如果我调用 Butterknife.bind(@NonNull Object target, @NonNull Dialog source) ,它只会注入(inject)该对话框中存在的 View 。

希望我已经清楚地解释了这个问题。

让我知道是否需要其他任何东西。

最佳答案

得到JW here的回复.

再次为他人陈述:

Create a view holder class for each layout and bind an instance of each individually. There's no way to support binding two layouts into one class.

关于android - Butterknife 将 View 绑定(bind)到不同的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46956047/

相关文章:

java - 无法解决 Android Studio 中的 : com. android.support :design:26. 2.0 错误

android - jBox2d android 绘制动态物体

android - 当你没有使用 unbind() 时究竟会发生什么?

android - Dagger 和 ButterKnife Android 的区别

java - 如何从异常跟踪堆栈中判断连接超时和套接字超时?

android - 如何在非 Eclipse Android 应用程序中正确包含支持库

android - 如何开发可用于任何应用程序中的任何文本的 Android 工具

android - Buttknife 不适用于 RXJava

Android:Dagger 2.4 不适用于 ButterKnife 8.0.1

Android:butterKnife - @BindView - 抛出 NPE