与 JDK 8 的数据绑定

Data Binding with JDK 8

正如我看到问题(Error:Data Binding does not support Jack builds yet)的回复,数据绑定还不支持JDK8(因为它需要在AS中启用JACK)。

不过,我从官方看到了数据绑定的用法,使用的是lambdas表达式。 (https://developer.android.com/topic/libraries/data-binding/index.html#listener_bindings)

自从我开始使用 API 24(需要 JDK 8)的数据绑定测试应用程序后,有什么方法可以使用 JDK 8 的数据绑定???

 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent">
      <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:onClick="@{() -> presenter.onSaveClick(task)}" />
  </LinearLayout>

是的,目前尚不支持 Jack Build,但您可以在 XMl 文件中使用 lambda 表达式。

作为yigit的更新https://code.google.com/p/android/issues/detail?id=210615#c11

These issues do not affect all apps and are not specific to data binding (any annotation processor can hit them). We'll release an experimental integration in 2.3 and also working on fixing those issues.

不过,如果您想将 lambda 与数据绑定一起使用,您可以使用它。但是,如果您想要 java 中的其他功能,则不能。