I need to add a fragment to a view dynamically as it's also inside a fragment (see the answer https://stackoverflow.com/a/6847770/811405).
The whole structure is like this:
Fragment
|
|---ViewHolder
|
|---(dynamically added fragment)
In my viewholder, I have access to the view. I've first thought that I could call getContext()
and then cast it to activity, then use it's fragment manager to add it. However, getContext
returns my Application object, not the activity (it's called on app launch before app is physically on the screen, so maybe the activity hasn't been created yet).
How can I add fragment dynamically on ViewHolder? (of course, without using terrible anti-patterns)