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 ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
You can do something like this:
fm=getActivity().getSupportFragmentManager();
{
fm.beginTransaction().replace(Containername, new CurrentFragmentname, CurrentFragment.class.getName()).commit();
}