数据绑定通用变量 [英] Data binding generic variable
本文介绍了数据绑定通用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何定义数据绑定变量的通用类型?
How to define generic type of a data binding variable?
以下代码从不编译.
<data>
<variable
name="viewModel"
type="com.example.viewmodel.ViewModel<Model>"/>
</data>
推荐答案
您需要如下所示对< Model>进行转义:
You need to escape <Model> as shown below:
<data>
<variable
name="viewModel"
type="com.example.viewmodel.ViewModel<Model>"/>
</data>
Android Studio仍然会显示无法解析符号"错误,但是XML会编译.这是一个已知问题.来自 Android Studio对数据绑定的支持:
Android Studio will still show a "Cannot resolve symbol" error, but the XML will compile. It is a known issue. From Android Studio Support for Data Binding:
注意:没有错误时,数组和通用类型(例如Observable类)可能会显示错误.
Note: Arrays and generic types, such as the Observable class, might display errors when there are no errors.
这篇关于数据绑定通用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文