[英]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.