https://kotlinlang.org logo
Title
l

locke

07/29/2019, 11:27 PM
Anyone have any idea why a BindingAdapter is being recognized at compile time as available, but at runtime during view inflation, the adapter is not called? It's as if the Xml parser is just skipping right over those attributes
m

Mark Murphy

07/29/2019, 11:31 PM
l

locke

07/29/2019, 11:34 PM
It's a standard Kotlin extension binding. Single argument extended off of View that sets a value on the view
Looks functionally identical to yours
My initial thought was that extending
View
rather than a subtype isnt allowed. But I have done so before...
m

Mark Murphy

07/29/2019, 11:37 PM
Extending
View
should be fine. Anything unusual about the binding expression in the layout? For example, are you not matching on data types for the value?
l

locke

07/29/2019, 11:42 PM
I am not, is that a requirement? I thought you could pass primitives without a data type? The in xml line is:
app:pcuDefault="true"
m

Mark Murphy

07/29/2019, 11:44 PM
Change that to
app:pcuDefault="@{true}"
and see if that works. It has to be a binding expression with the
@{}
syntax, as the data binding system ignores ordinary XML attributes. I have not tried a boolean constant as the binding expression, though.
w

Will Shelor

07/30/2019, 12:34 AM
make sure you set your lifecycle observer, too
on the binding
m

Mark Murphy

07/30/2019, 11:13 AM
that only matters if you are binding a
LiveData
-- in this case, it's a constant
l

locke

07/30/2019, 9:33 PM
Ended up driving and not replying, but @Mark Murphy that both was the challenge and is indeed something you can do. Data binding is perfectly happy with constants passed in like that. Thank you for the help!
👍 1