android - How do I add a fragment to a view when its context is Application? -
i need add fragment view dynamically it's inside fragment (see answer https://stackoverflow.com/a/6847770/811405).
the whole structure this:
fragment | |---viewholder | |---(dynamically added fragment)
in viewholder, have access view. i've first thought call getcontext()
, cast activity, use it's fragment manager add it. however, getcontext
returns application object, not activity (it's called on app launch before app physically on screen, maybe activity hasn't been created yet).
how can add fragment dynamically on viewholder? (of course, without using terrible anti-patterns)
my real problem inflating layout incorrect context (yup, guessed right, application instance) instead of activity. i've fixed code make inflate activity, , getcontext
returns activity. fragment manager , add fragment normally.
Comments
Post a Comment