[英]Android resource linking failed in binding adapter data binding
我想使用綁定適配器設置文本。這是 MyBindingAdapter.kt
@BindingAdapter("android:setTitle")
fun setTitle(textView : TextView,text: String){
textView.text = text
}
在 activity_table.xml 我這樣使用 setTitle
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight="1"
android:gravity="center"
android:setTitle="Hello word"/>
您需要在@BindingAdapter("android:setTitle")
更改為@BindingAdapter("setTitle")
。
您還需要將 xml 文件從android:setTitle="Hello word"
更改為setTitle="Hello word"
它現在應該工作了!
Android studio在綁定的時候不會考慮@BindingAdapter("android:setTitle")
,你只需要寫@BindingAdapter("setTitle")
就可以完美的執行,否則編譯時會報綁定錯誤。
首先確保您必須將布局包含在<layout>
標記中
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
..... </layout>
和@BindingAdapter("android:setTitle")
更改為@BindingAdapter("title")
它應該工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.