Solution 1 :
just run this
getActivity().getSupportFragmentManager().beginTransaction().detach(this).attach(this).commit();
Problem :
everyone, my issue is :
I’m in ProfilFragment, that was generated with the Menu Drawer it extends Fragment, and I can’t change this (it broke some other part).
When I click on a button I want to refresh my current Fragment
// Reload current fragment
Fragment frg = null;
frg = getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_profil);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
I found this on other StackOverflow issues but it didn’t work for me.
frg = getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_profil);
Always return null
Even if in my mobile_navigation.xml
I have
<fragment
android_id="@+id/nav_profil"
android_name="com.example.pierregignoux.ui.profil.ProfilFragment"
tools_layout="@layout/fragment_profil" />
Any help would be great, Thanks a lot.
Comments
Comment posted by iCantC
just out of curiosity, why you want to reload a
Comment posted by Beatles BOB
I add some db data to firebase to an Mpandroidchart, and it doesn’t reload when data change
Comment posted by stackoverflow.com/questions/47303952/…
can you please check this link,
Comment posted by Beatles BOB
For me nothing happen 🙁
Comment posted by Beatles BOB
So I do like getActivity().getSupportFragmentManager().beginTransaction().detach(ProfilFragment.this).attach(ProfilFragment.this).commit(); but I receive Cannot detach Fragment attached to a different FragmentManager. Fragment ProfilFragment{ab662d} (22d9d467-dcfc-4dbc-8b00-fe827083f6a0) id=0x7f0900f6} is already attached to a FragmentManager.
Comment posted by Amit pandey
dont use ProfilFragment.this just use this