BindingAdapter code:
@BindingAdapter(value = ["vertical_divider_decorator_drawable"], requireAll = false)
@JvmStatic
fun bindRecyclerViewDivider(recyclerView: RecyclerView, vertical_divider_decorator_drawable: Drawable) {
val decorator = DividerItemDecoration(recyclerView.context, RecyclerView.VERTICAL)
decorator.setDrawable(vertical_divider_decorator_drawable)
recyclerView.addItemDecoration(decorator)
}
@BindingAdapter(value = ["vertical_divider_decorator_drawable"], requireAll = false)
@JvmStatic
fun bindRecyclerViewDivider(recyclerView: RecyclerView, vertical_divider_decorator_drawable: Int ) {
val decorator = DividerItemDecoration(recyclerView.context, RecyclerView.VERTICAL)
ResourcesCompat.getDrawable(recyclerView.context.resources, vertical_divider_decorator_drawable, null)
?.let { drawable -> decorator.setDrawable(drawable) }
recyclerView.addItemDecoration(decorator)
}
RecyclerView in XML:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:vertical_divider_decorator_drawable="@drawable/row_divider"
android:id="@ id/list"
/>
Build error:
AAPT: error: attribute vertical_divider_decorator_drawable (aka com.package:vertical_divider_decorator_drawable) not found.
BindingAdapter has both Drawable and Int parameters but still the compiler not accepting both drawbales.
CodePudding user response:
Try to change from:
app:vertical_divider_decorator_drawable="@drawable/row_divider"
to:
app:vertical_divider_decorator_drawable="@{@drawable/row_divider}"
If not helped, try this:
fun bindRecyclerViewDivider(recyclerView: RecyclerView, vertical_divider_decorator_drawable: Int) {