Skip to content Skip to sidebar Skip to footer

How We Can Remove Dynamically Added Fragments From Layout

Can any one help me. I have a Fragment say FRAGMENT A and am adding it to a layout dynamically...Suppose i have added 3 instance of FRAGMENT A to that layout.Then How i can Remove

Solution 1:

it's actually pretty simple:

let's say you added the fragment like this:

fragmentTransac.add(R.id.content, fragA);

instead, you'll add it with a TAG too

fragmentTransac.add(R.id.content, new FragA(), "first");
// then the other
fragmentTransac.add(R.id.content, new FragA(), "second");

then to remove:

Fragment f = getFragmentManager().findFragmentByTag("first");
if(f!=null) fragmentTransac.remove(f);
fragmentTransac.commit();

happy coding =]

Post a Comment for "How We Can Remove Dynamically Added Fragments From Layout"