简体   繁体   English

标识符必须具有XML文件中的用户定义类型,并带有observablefield的数据绑定

[英]Identifiers must have user defined types from the XML file, databinding with observablefield

I want my view visibility to be dependent on condition behaviour so I am using ObservableField and with databinding trying to change view visibility but getting issue like "Identifiers must have user defined types from the XML file. InputType is missing it" 我希望视图可见性取决于条件行为,因此我正在使用ObservableField并通过数据绑定尝试更改视图可见性,但遇到类似“标识符必须具有XML文件中用户定义的类型。InputType丢失的问题”

Code: 码:

Kotlin File

var showView: ObservableField<Boolean>? = ObservableField(false)

//API call response
showView.set(true)


Layout File:

<TextView
 android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="@{viewModel.showView ? View.VISIBLE : View.GONE}"/>

How to apply databinding with Observablefield of type boolean? 如何使用类型为boolean的Observablefield进行数据绑定? I have used it for string text also and it's working but not working with boolean conditional statement. 我也将它用于字符串文本,它可以工作,但不能与布尔条件语句一起工作。

I am not sure if that's the case here, but this error message is usually displayed when you reference a type in your binding expressions that hasn't been declared in the <data> section of your layout. 我不确定情况是否如此,但是当您在绑定表达式中引用尚未在布局的<data>部分中声明的类型时,通常会显示此错误消息。 The same way you declare the View type as an import, you should declare the type InputType . View类型声明为导入的方法相同,应该声明InputType类型。

<data>
    <!-- Maybe an import for InputType is missing here? -->
    <import type="android.view.View" />
    <variable
        name="viewModel"
        type="com.yourpackage.YourViewModel"/>
</data>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据绑定未获得“标识符必须具有XML文件中的用户定义类型”错误 - data binding not getting “Identifiers must have user defined types from the XML file” error Android数据绑定 - 错误:(119,29)标识符必须具有XML文件中的用户定义类型。 main_radio_subscribe缺少它 - Android Data binding - Error:(119, 29) Identifiers must have user defined types from the XML file. main_radio_subscribe is missing it 双向数据绑定(在xml中),ObservableField,BaseObservable,我应该用哪个双向数据绑定? - Two-way databinding(in xml), ObservableField, BaseObservable , which one I should use for the two-way databinding? 数据绑定 - ObservableField<String> 不更新视图 - Databinding - ObservableField<String> not updating view 如何格式化ObservableField(double)DataBinding? - How to format an ObservableField (double) DataBinding? 数据绑定:自定义对象的ObservableField无法正常工作 - Databinding: ObservableField of custom object it is not working properly ObservableField 的使用<string> Android 数据绑定中的字符串</string> - Usage of ObservableField<String> over String in Android Databinding 数据绑定必须包含布局文件 - databinding must include a layout file 如何处理警告:未经检查调用 &#39;ObservableField(T)&#39; 作为原始类型 &#39;android.databinding.ObservableField&#39; 的成员 - How to handle warning:Unchecked call to 'ObservableField(T)' as a member of raw type 'android.databinding.ObservableField' 使用ObservableField &lt;&gt;,set()的双向数据绑定不起作用? - 2-way databinding with ObservableField<>, set() doesn't work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM