Android数据绑定类不会立即更新

Android数据绑定类不会立即更新,android,layout,data-binding,android-databinding,Android,Layout,Data Binding,Android Databinding,问题: 我现在正在处理一个集成了数据绑定的项目,每当我创建一个新布局或向现有布局添加一个视图时,它都不会出现在绑定对象中,我甚至尝试重建和清理该项目,但它不起作用,我只需重新启动该项目或重命名布局文件一两次即可更新该布局文件BindingClass。这太烦人了,占用了我重要的时间 代码 dataBinding { enabled = true } <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android=

问题:

我现在正在处理一个集成了数据绑定的项目,每当我创建一个新布局或向现有布局添加一个视图时,它都不会出现在绑定对象中,我甚至尝试重建和清理该项目,但它不起作用,我只需重新启动该项目或重命名布局文件一两次即可更新该布局文件
BindingClass
。这太烦人了,占用了我重要的时间

代码

dataBinding {
    enabled = true
}
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <RelativeLayout
        android:id="@+id/lyt_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View android:id="@+id/old_view_1" .../>
        <View android:id="@+id/old_view_2" .../>    

        <!-- New View -->
        <View android:id="@+id/new_view" .../>
    </RelativeLayout>
</layout>
建造等级

dataBinding {
    enabled = true
}
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <RelativeLayout
        android:id="@+id/lyt_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View android:id="@+id/old_view_1" .../>
        <View android:id="@+id/old_view_2" .../>    

        <!-- New View -->
        <View android:id="@+id/new_view" .../>
    </RelativeLayout>
</layout>
布局文件

dataBinding {
    enabled = true
}
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <RelativeLayout
        android:id="@+id/lyt_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View android:id="@+id/old_view_1" .../>
        <View android:id="@+id/old_view_2" .../>    

        <!-- New View -->
        <View android:id="@+id/new_view" .../>
    </RelativeLayout>
</layout>
而且平台支持还不是很成熟,我使用数据绑定已经很久了,所有与IDE相关的问题都解决了,但是你的问题也经常发生在我身上

对我来说最快的解决办法是

  • 文件>关闭项目
  • 从最近开始打开
这几乎需要5秒钟。并生成所有新添加的字段和布局绑定类


它比重建或重新启动快。

除非您重建项目,否则它不会运行,因为这就是
代码生成
的工作方式。你们知道如何重建项目,对吗@Umer Khan您可以
重建
项目,或者
关闭
项目,然后
重新打开
它只需
重建项目
,您就不必重新启动项目。您是否尝试使缓存无效?文件-»使缓存无效/Restart@UmerKhan只需再次同步您的项目