Hi am tryin to use data binding to bind a drawable res ID into a textview via code but i keep getting this error:
Cannot find a getter for <android.widget.TextView android:background> that accepts parameter type 'int'
If a binding adapter provides the getter, check that the adapter is annotated correctly and that the parameter type matches.
Here is the viewModel code
@DrawableRes
private var buttonBg: Int = R.drawable.white_btn
@Bindable
fun getButtonBg(): Int {
return buttonBg
}
@Bindable
fun setButtonBg(bgRes: Int) {
if (buttonBg != bgRes) {
buttonBg = bgRes
notifyPropertyChanged(BR.buttonBg)
}
}
xml
<TextView
android:id="@+id/toggle_textButton"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@={viewModel.buttonBg}"
android:padding="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/follow" />