Reload Fragment

自古美人都是妖i 提交于 2019-12-20 02:59:17

问题


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();
}


来源:https://stackoverflow.com/questions/14097225/reload-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!