Hello! There is a sliding navigation bar + TAB of 3 tabs. Each tab loads its fragment, when switching between tabs, everything loads correctly, but when you click on the side menu tab, you need to reload the current fragment and update the contents of the fragment with new data obtained from the database, I get the data from the database correctly, but I can’t overwrite the fragment. I tried to replace , detach , attach - did not help.

I tried this:

 FragmentMainPic fragmentMainPic = (FragmentMainPic) getSupportFragmentManager().findFragmentById(R.id.fragment_main); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.detach(fragmentMainPic); ft.attach(fragmentMainPic); ft.commit(); 

Here for some reason fragmentMainPic returns null

and so, here ft loaded, newInstance triggered, but the data is not updated

 FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentMainPic fragmentMainPic = FragmentMainPic.newInstance(1); ft.replace(R.id.fragment_main,new FragmentMainPic ()); ft.commit(); 

There is a suspicion that somehow you need to be updated through the interface

  • In the second example, you need, in the second parameter of the replace function, to add not a new class object, but the one that was created before this function, that is, instead of new FragmentMainPic (), write fragmentMainPic. Is not it? - YungBlade
  • No, it does not update either. Is there some kind of working example where the same fragment is updated on the viewpager when you click on the navigation drawer? - Ali Isfandiyarov

0