首页 > 解决方案 > 为什么我不能在 Android Studio 中定义 type="LiveData<Int>"?

问题描述

代码A可以正常工作,我不知道为什么代码b不能工作,你能告诉我吗?

代码 A

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>        
        <import type="androidx.lifecycle.LiveData" />

        <variable
            name="MyValue1"
            type="LiveData&lt;Integer>" />
    </data>
   ...

代码 B

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>        
        <import type="androidx.lifecycle.LiveData" />

        <variable
            name="MyValue2"
            type="LiveData&lt;Int>" />
    </data>
   ...

标签: android

解决方案


因为Int不是 用于数据绑定的表达式语言的一部分


推荐阅读