android - : 属性 mutableText (aka yodgorbekkomilov.edgar.footballapp:mutableText) 未找到。?
问题描述
我正在开发一个足球静态应用程序,我使用了绑定适配器,但在我的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
使用过的课程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>()
我试图解决的问题:
- 使缓存重新启动无效
- 遵循此Android Binding Adapter 属性未找到链接。尝试了建议的答案,但它没有解决我的问题
为了避免这个问题,我必须做什么?任何帮助和建议将不胜感激。
解决方案
我已经更改了我的 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>
推荐阅读
- azure-data-explorer - ExtentsDrop 每 1 小时运行一次,尽管数据非常新鲜并保留了一个月
- directory - 使用python从ftp服务器上的多个/不同目录下载文件
- dropzone.js - 如何模拟 FileList 以测试 JS?
- javascript - 如何将嵌套对象插入另一个对象
- python - 是否可以使用 matplotlib 图例选择器选择图例文本区域而不是图例行?
- riscv - 在裸机 risc-v 中,我需要如何以及需要哪些工具使用尖峰?
- docker - docker-compose healthcheck for pentaho data integration (pdi)
- c# - Json.Net 自定义 ContractResolver 忽略自定义对象
- css - 在 Chrome 和/或 Firefox 中复制 -webkit-mask-composite:destination-atop 的任何方式?
- flutter - 颤振分析在本地工作,但在 github 操作中失败