Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart fragment inside activity

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.

enter image description here

like image 906
Ricardo Filipe Avatar asked Dec 21 '12 11:12

Ricardo Filipe


People also ask

How do I refresh a fragment from another fragment?

You can access another Fragment by its tag: // find your fragment YourFragment f = (YourFragment) getSupportFragmentManager(). findFragmentByTag("yourFragTag"); // update the list view f. updateListView();

How do I refresh a ViewPager fragment?

OnPageChangeListener is the correct way to go, but you will need to refactor your adapter a bit in order to keep a reference to each Fragment contained in the FragmentPagerAdapter. Then, instead of creating a new Fragment, use the one contained in the adapter: mViewPager. addOnPageChangeListener(new ViewPager.


1 Answers

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

like image 154
Manoj Kumar Avatar answered Sep 30 '22 01:09

Manoj Kumar