https://kotlinlang.org logo
#android
Title
# android
s

Seri

06/21/2018, 2:49 PM
Does Kotlin’s view binding work with layouts located in other modules? I’m getting the error
Unresolved reference: account_card
from the following line:
import kotlinx.android.synthetic.main.account_card.view.*
There was a similar stackoverflow question posted a few months ago, but it didn’t get any response. https://stackoverflow.com/questions/48808542/android-kotlin-kotlinx-module-level-view-binding
r

rkeazor

06/21/2018, 4:01 PM
Is that layout actually inflated? I would think that wouldn’t be the best approach. Like if I have a lib module and I was to access its layouts views, than it should exposed via that actual module. perhaps via getter/setter properties
never the less, I think it will also depend if both modules have applied the plugin or have the right visibility scope. than you can probably do viewFromModule.[the binded view you want]
p

pdegand

06/21/2018, 4:13 PM
this is not supported yet. Feel free to star/follow this issue https://youtrack.jetbrains.com/issue/KT-22430
s

Seri

06/21/2018, 4:19 PM
Thanks @pdegand! I’ll keep an eye on that ticket
@rkeazor in this case, I’m writing an Adapter for a RecyclerView, so I’m addressing instances of views, rather than views as local variables.
Calling them as
itemView.name.text
works fine
Either way, I’ve flattened that module out and into the main module and its working fine. Thanks again, @pdegand!
r

rkeazor

06/21/2018, 4:37 PM
but shouldn’t that be address via <dataSet> ? maybe I’m misreading what your saying lol. Glad you figured it out. Also be careful I think that view caching isn’t available outside of the activity or fragment. It was an experimental feature last time I checked
4 Views