Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" />

This is the custom view I have in my xml

and a method to bind textAbove to this view

@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))
}

But when I compile this I am getting Error:error: attribute 'app:textAbove' not found.

like image 394
Nitin Mesta Avatar asked Nov 23 '17 07:11

Nitin Mesta


Video Answer


1 Answers

Change

app:textAbove="Nitin"

to

app:textAbove='@{"Nitin"}'

another way

// app:textAbove="@{@string/nitin}"  text from String resource
// app:textAbove="@{viewModel.nitin}" text from ViewModel
like image 152
Linh Avatar answered Oct 04 '22 12:10

Linh