【问题标题】:DataBinding Component is not converted into ObjectDataBinding 组件未转换为 Object
【发布时间】:2019-11-10 03:07:56
【问题描述】:

我正在尝试使用 databinding 从视图模型中将 Cardviewvisibility 与基于条件的 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


    【解决方案1】:

    我不知道为什么,但是当我今天尝试运行我的代码时,它运行良好。 我昨天尝试了干净的代码并使缓存无效并重新启动,但它没有工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多