-1

I have a user interface divided into two blocks, a menu panel which is the same all the time, and a content which changes depending on the menu entry which is selected.

To change the content fragment dynamically i have to replace the current fragment by the new one, as explained in this SO question : Replacing a fragment with another fragment inside activity group

The problem is that the "current" fragment is not only one fragment, but two : the panel AND the content. So if I attempt to replace i assume that both fragments will be replaced by the new content fragment, which is not what i want.

Is there a way to replace one particular fragment with removing other present fragments, if any ? Thank you.

Community
  • 1
  • 1
Virus721
  • 8,061
  • 12
  • 67
  • 123
  • The documentation says : `"Replace an existing fragment that was added to a container. This is essentially the same as calling remove(Fragment) for all currently added fragments that were added with the same containerViewId and then add(int, Fragment, String) with the same arguments given here."`, so no, it does not. – Virus721 Mar 05 '15 at 08:25

2 Answers2

0

You can easily replace single fragment with FragmentTransaction#replace method. Suppose you want to replace a fragment in a Framelayout, you can do it as shown below:

getFragmentManager().beginTransaction()
                    .replace(R.id.container, newFragment, null).commit();

Here R.id.container is id of the FrameLayout and newFragment is the Fragment you want to put in layout.

jimmy0251
  • 16,293
  • 10
  • 36
  • 39
0

I guess you have to have two fragments in the content block. For the first fragment you would be setting a weight of 1 so that it occupies full content block unless you want your second fragment in the block to be visible.you would be setting visibility of that second fragment in content block to "gone" if you want only one fragment to be visible or else give it some weight or layout width and layout height for both the fragments to be visible.

dora
  • 2,047
  • 3
  • 18
  • 20