Restart fragment inside activity

2019-02-18 10:35发布

问题:

I have a litle doubt.

I have an activity that have 3 fragment inside. I need to restart the state of one of these fragments. Restart only one.

回答1:

Old, but may be useful to someone else. To refresh the fragment, you need to detach the fragment and reattach it

Fragment frg = null;
frg = getFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();

Your_Fragment_TAG is the name you gave your fragment when you created it