[英]Android Binding Adapter not working for CustomView
<com.myapp.view.widgets.TextImageTextView
android:id="@+id/tv_on_boarding_step_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"
app:layout_constraintBottom_toTopOf="@+id/appCompatButton"
app:layout_constraintEnd_toStartOf="@+id/space_one_two"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/label_description"
app:textAbove="Nitin" />
这是我在xml中的自定义视图
以及将textAbove绑定到此视图的方法
@BindingAdapter("app:textAbove")
fun setTextAbove(view: TextImageTextView, textAbove: Int) {
// this is the method I have in my custom view
view.setTextAbove(view.context.getString(textAbove))
}
但是当我编译它时,我收到错误:错误:找不到属性'app:textAbove'。
更改
app:textAbove="Nitin"
至
app:textAbove='@{"Nitin"}'
其他方式
// app:textAbove="@{@string/nitin}" text from String resource
// app:textAbove="@{viewModel.nitin}" text from ViewModel
在xml中添加以下行:
xmlns:app="http://schemas.android.com/apk/res-auto"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.