簡體   English   中英

Android Binding Adapter不適用於CustomView

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM