如何解决Android 数据绑定 <include> 变量使用 interface
我将布局用作几个稍微不同的模型之间的公共 UI 块,表示为公共界面的扩展,即 interface PostViewModelBase : UserContentViewModelBase
。此接口的对象作为数据绑定中的变量传递到布局中:
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<data>
...
<variable
name="model"
type="...PostViewModelBase"
/>
...
</data>
...
<include layout="@layout/v_uc_social_featured"
app:model="@{model}"
/>
...
v_uc_social_featured.xml
看起来像这样:
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<data>
<import type="android.view.View" />
<variable
name="model"
type="...UserContentViewModelBase"
/>
...
它以前有效,但在我将 com.android.tools.build:gradle
从 3.5.0
带到 4.1.1
并将 Android 视图绑定添加到项目后,现在停止工作。错误如下:
Cannot find a setter for <...VUcSocialFeaturedBinding app:model> that accepts parameter type '...PostViewModelBase'
If a binding adapter provides the setter,check that the adapter is annotated correctly and that the parameter type matches.
有没有办法让它重新工作?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。