gpt4 book ai didi

android - 在布局中使用 MutableLiveData 变量时,数据绑定(bind)停止工作 [Gradle 到 3.5.1]

转载 作者:行者123 更新时间:2023-12-03 05:32:53 25 4
gpt4 key购买 nike

我在我的项目中使用 DataBinding。使用 Java,而不是 Kotlin,Android Studio 版本是 3.5.1(最新)

将项目 gradle 版本从 3.5.0 升级到 3.5.1 后,*BindingImpl 类中出现错误。
我发现问题出在我的一个布局文件中的 MutableLiveData

试图清理项目并重新启动 Android Studio。但唯一有效的是将 gradle 版本设置回 3.5.0

这是我的布局

<?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">

<data>

<import type="androidx.lifecycle.MutableLiveData" />

<variable
name="hintText"
type="String" />

<variable
name="helperText"
type="String" />

<variable
name="collection"
type="Object" />

<variable
name="selection"
type="MutableLiveData" /> // this one is breaks down in 3.5.1

<variable
name="enabled"
type="Boolean" />

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:setupSpinnerHint="@{true}">

<kz.jgroup.android.umag.base.view.customs.ResizableItemsSpinner
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:adapterWith="@{collection}"
android:background="@drawable/spinner_outlined_box"
android:enabled="@{enabled == null ? true : enabled}"
android:paddingStart="12dp"
android:paddingTop="26dp"
android:paddingEnd="32dp"
android:paddingBottom="17dp"
android:selectedItem="@={selection}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:textSize="16sp"
tools:listitem="@layout/item_spinner_inline" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="@color/white"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="@{hintText}"
android:textColor="@color/focusable_color"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Подсказка" />


<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/helper_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="5dp"
android:emptyToGone="@{helperText}"
android:textColor="@color/focusable_color"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/hint"
app:layout_constraintTop_toBottomOf="@+id/spinner"
tools:text="Вспомогательное сообщение" />

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>


这是我得到错误的地方以及 DataBinding 生成的内容

使用版本 3.5.1
        boolean enabledJavaLangObjectNull = false;
? selectionGetValue = null; //Illegal start of expression
java.lang.Object collection = mCollection;
boolean enabledJavaLangObjectNullBooleanTrueEnabled = false;
java.lang.String helperText = mHelperText;
androidx.lifecycle.MutableLiveData<?> selection = mSelection;
java.lang.String hintText = mHintText;
java.lang.Boolean enabled = mEnabled;

在 3.5.0 版本中生成的代码看起来:
        boolean enabledJavaLangObjectNull = false;
java.lang.Object selectionGetValue = null;
java.lang.Object collection = mCollection;
boolean enabledJavaLangObjectNullBooleanTrueEnabled = false;
java.lang.String helperText = mHelperText;
androidx.lifecycle.MutableLiveData selection = mSelection;
java.lang.String hintText = mHintText;
java.lang.Boolean enabled = mEnabled;

我预计随着从稳定版 3.5.0 升级到稳定版 3.5.1 一切都会好起来的,但正如您所见并非如此((

最佳答案

关于android - 在布局中使用 MutableLiveData 变量时,数据绑定(bind)停止工作 [Gradle 到 3.5.1],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58305483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com