Is there a Kotlin language feature that could reduce the verbosity of accessing views from our classes with Data Binding? According to this (https://android-review.googlesource.com/c/platform/frameworks/support/+/882241) kotlinx.android.synthetic is no longer recommended. And since I use the data binding library already I figured I’d remove all those imports and just use data binding to access the views. However I end up with a lot of calls such as
. But also data binding exposes even nested views:
binding.nested
works even if
nested
is child of child of child … of the root
wasyl
10/09/2019, 4:53 PM
kotlinx.android.synthetic is no longer recommended
Last I saw discussion about this it turned out that
androidx.synthetic
isn’t “not recommended” overall, it’s just not recommended in the aosp repo
p
Paul Dhaliwal
10/09/2019, 5:07 PM
Do you mean that by calling binding.nested I should from there have access to all views in the layout? I’m not seeing that field in under binding. That would be great as I could just save that value as ” val layout” for example and access all views in the layout from there, if I’m understanding correctly.
w
wasyl
10/09/2019, 5:11 PM
I mean that the binding class should have top-level fields for all views in the layout, even nested ones. So it’s enough to store
binding
in the field, and then you should be able to call
binding.topLevelView
,
binding.someChild
,
binding.someVeryDeeplyNestedChildView
p
Paul Dhaliwal
10/09/2019, 5:13 PM
Ah I see. No that doesn’t work for me. I don’t see the child views when using binding, only the top level views. So I have to go binding.parentview.childview and not binding.childview. Is it possible I misconfigured something?