Restart fragment inside activity

前端 未结 1 1583
野趣味
野趣味 2021-01-13 05:40

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条回答
  • 2021-01-13 06:26

    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

    0 讨论(0)
提交回复
热议问题