: 未找到属性 mutableText(又名 yodgorbekkomilov.edgar.footballapp:mutableText)。?

: attribute mutableText (aka yodgorbekkomilov.edgar.footballapp:mutableText) not found.?

我正在开发一个足球静力学应用程序,我使用了绑定适配器,但我的 football_item.xml 文件中出现以下错误

C:\Users\Edgar\Desktop\FootballApp\app\src\main\res\layout\football_item.xml:17: AAPT: error: attribute mutableText (aka yodgorbekkomilov.edgar.footballapp:mutableText) not found.

¨

下面是我的 xml 文件,我在其中遇到错误

<?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">
<data>
    <variable
        name="viewModel"
        type="yodgorbekkomilov.edgar.footballapp.ui.FootballViewModel" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.clubName"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.countryName"/>





    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.clubValue"/>

    <ImageView
        app:imageUrl="@{viewModel.image}"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/clubImage"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.europeanTitle}"/>


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

下面是我的 bindingAdapter class 我用过 bindingadapter

@BindingAdapter("mutableText")
fun setMutableText(view: TextView, text: MutableLiveData<String>?) {
    val parentActivity:AppCompatActivity? = view.getParentActivity()
    if(parentActivity != null && text != null) {
        text.observe(parentActivity, Observer { value -> view.text = value?:""})
    }

下面是我的FootballListViewModel.kt

class FootballViewModel: BaseViewModel() {
    private val clubName = MutableLiveData<String>()

    private val countryName = MutableLiveData<String>()
    private val clubValue = MutableLiveData<Int>()
    private val clubImage = MutableLiveData<String>()
    private val europeanTitle = MutableLiveData<Int>()

    fun bind(football: FootballResponse){
        clubName.value= football[0].name
        countryName.value = football[1].country
        clubValue.value = football[2].value
        clubImage.value = football[3].image
        europeanTitle.value = football[4].europeanTitles

    }

    fun getClubName():MutableLiveData<String>{
        return clubName
    }

    fun getCountryName():MutableLiveData<String>{
        return countryName
    }

    fun getClubValue():MutableLiveData<Int>{
        return clubValue
    }

    fun getImage():MutableLiveData<String> {
 return clubImage

    }


    fun getEuropeanTitle():MutableLiveData<Int> {
        return europeanTitle

    }
}

下面是FootballResponseItem.kt

data class FootballResponseItem(
    @SerializedName("country")
    val country: String,
    @SerializedName("european_titles")
    val europeanTitles: Int,
    @SerializedName("image")
    val image: String,
    @SerializedName("name")
    val name: String,
    @SerializedName("value")
    val value: Int
)

下面是FootballResponse.kt

class FootballResponse : ArrayList<FootballResponseItem>()

我尝试解决的问题:

  1. 使缓存重新启动无效
  2. 已关注此 Android Binding Adapter attribute not found link。尝试了建议的答案,但没有解决我的问题

我必须做什么才能避免出现问题?任何帮助和建议将不胜感激。

我更改了我的 xml 文件,然后它开始工作了

<?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">
<data>
    <variable
        name="viewModel"
        type="yodgorbekkomilov.edgar.footballapp.ui.FootballViewModel" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.clubName}"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.countryName}"/>





    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.clubValue}"/>

    <ImageView
        app:imageUrl="@{viewModel.image}"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.europeanTitle}"/>


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>