r/android_devs • u/UselessAccount45721 • Jun 14 '20
Help Getting Viewmodel into Custom/Compound view?
Do you guys have any suggestions? I'm using Navigation components which is what makes this tough. Do I just have an interface without worrying about Navigation components at all? Thanks so much.
11
Upvotes
3
u/anemomylos 🛡️ Jun 14 '20
Hi.
Using the "Help" flair makes it easier for others to locate a post asking for help.
2
6
u/Zhuinden EpicPandaForce @ SO Jun 14 '20
It depends on what you want to do. Where there's a will, there's a way. You can get the Fragment via
findFragment(), you can get the Activity through the base context chain, and you can get the NavController through the context too so you can even find theNavBackStackEntry.But the simplest way to do it would be to have an interface in the custom view, implemented by the host fragment, the host fragment sets itself as the implementation of this interface and then the Fragment talks to the ViewModel.