【发布时间】:2019-11-10 03:07:56
【问题描述】:
我正在尝试使用 databinding 从视图模型中将 Cardview 的 visibility 与基于条件的 boolean 绑定。
但我收到数据绑定错误
我尝试在 xml 本身内部使用数据绑定和处理 visibility。
我还尝试从片段中以编程方式处理visibility。
但是两个例子都失败了
<variable name="vm"
type="packageName.ui.viewmodels.DashHomeViewModel"/>
android:visibility="@{vm.showQRCard == true ? View.VISIBLE : View.GONE}"
val binder = DataBindingUtil
.inflate(inflater, R.layout.fragment_dash_home, container, false)
binder.vm = viewModel
我收到此错误消息。
错误:FragmentDashHomeBinding 类中的构造函数 FragmentDashHomeBinding 不能应用于给定类型; 超级(绑定组件,根,2 ^ 必需:Object,View,int,AppBarLayout,LinearLayout,LinearLayout,ImageView,SwipeRefreshLayout,Toolbar,CircleImageView,TextView,TextView,TextView,FrameLayout,FrameLayout,FrameLayout,FrameLayout 找到:DataBindingComponent,View,int,AppBarLayout,LinearLayout,LinearLayout,ImageView,ImageView,SwipeRefreshLayout,Toolbar,CircleImageView,TextView,TextView,TextView,TextView,FrameLayout,FrameLayout,FrameLayout,FrameLayout 原因:实际参数列表和形式参数列表的长度不同
我从错误中了解到的是 Object 是预期的,但 DataBindingComponent 已通过,但 DataBindingComponent 会自动转换为 object 在这种情况下不会发生。
我不知道这背后的原因。
在这种特定情况下发生这种情况只是因为其他片段中用于可见性的类似代码运行良好。
【问题讨论】:
标签: android android-layout kotlin data-binding android-databinding