2

I am working on a navigation drawer and am currently using:

getSupportFragmentManager().beginTransaction().replace(R.id.mainfragment, f1).commit();

but as you can see that always replaces the main fragment with the new one. Thanks!

Engima
  • 49
  • 6
  • This method replaces whatever fragment you have in the container with id `mainfragment`. If you want to replace another one, select the id of its container. Remember you also have other methods than replace, like add that allows you to overlap fragments in the same container. – droidpl Oct 04 '15 at 20:01

2 Answers2

1

You can do beginTransaction().replace (container, newFragment, tag), where container is the id of a ViewGroup in an xml file. So the thing being replaced is whichever fragment is currently in the container.

geokavel
  • 619
  • 4
  • 12
1
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(getId(), new SearchVideoDownloadFragment(), "NewFragmentTag");
ft.commit();
Nir Duan
  • 6,164
  • 4
  • 24
  • 38