Search code examples
javaandroidandroid-fragmentsandroid-actionbarfragment

Reload Fragment


I am just curious, as I have set up Fragment tabs in a FragmentActivity, how to reload a fragment either from the FragmentActivity, or from the Fragment itself, to just purge and reload that tab. I essentially need the same thing that happens when I reselect the tab to happen, when it replaces the fragment. Is there a simple way to do this and reload the fragment ?


Solution

  • Create a method that begins a FragmentTransaction, detaches the fragment, and commits. Then begin a new FragmentTransaction which attachs the fragment and commits. This should destroy the view hierarchy, create it again, attach it to the UI and display it. Whenever you need the fragment refreshed, jsut call this method.