Android :未找到属性mutableText(又名yodgorbekkomilov.edgar.FootballPP:mutableText)。?
我正在开发一个足球静态应用程序,我使用了绑定适配器,但在我的Android :未找到属性mutableText(又名yodgorbekkomilov.edgar.FootballPP:mutableText)。?,android,kotlin,mvvm,data-binding,two-way-binding,Android,Kotlin,Mvvm,Data Binding,Two Way Binding,我正在开发一个足球静态应用程序,我使用了绑定适配器,但在我的football\u 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
football\u 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>
下面是我的足球列表视图模型.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
}
}
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
)
class FootballResponse : ArrayList<FootballResponseItem>()
下面是足球响应.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
}
}
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
)
class FootballResponse : ArrayList<FootballResponseItem>()
class football响应:ArrayList()
我试图解决的问题是:
为了避免这个问题,我必须做些什么?任何帮助和建议都将不胜感激。我已经更改了我的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>
我随后更改了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>
在一些可变文本语句中,似乎缺少了一些花括号<代码>应用程序:mutableText=“@{viewModel.clubValue”。这是一个格式错误还是在你的代码中?如果是后者,你可能应该纠正它。@Cheesebaron我已经解决了这个问题,但现在我遇到了另一个问题,也许你可以检查一下post。请继续,把答案放在这里。看起来你的一些变量中缺少了一些小括号xt语句。app:mutableText=“@{viewModel.clubValue”
。这是一个格式错误还是实际上在你的代码中?如果是后者,你可能应该纠正它。@Cheesebaron我已经解决了这个问题,但现在我遇到了另一个问题,也许你可以检查一下post。请继续,把答案放在这里。