0

When I load a fragment twice, it just gets loaded above the contents of the same fragment that was loaded earlier.

I have this code to load it -

Fragment newFragment = new GridFragment();
                FragmentTransaction ft = getFragmentManager().beginTransaction();
                ft.add(R.id.gridFrame, newFragment).commit();

// gridFrame is the FrameLayout over which I replace it with the fragment

How do I just refresh the fragment and not load again above the prior contents ?

Gissipi_453
  • 1,250
  • 1
  • 25
  • 61
  • 2
    give your fragment a tag while adding and then refer that fragment using the same tag for e.g - > `(GridFragment) getFragmentManager().findFragmentByTag("YOUR_TAG")` – Satyen Udeshi Oct 02 '15 at 12:04
  • 1
    If you set the Background color to white for all the Layouts of the Fragment, your content might not be conflict or gets loaded above the contents of the same fragment that was loaded earlier. – Jaimin Modi Oct 02 '15 at 12:07
  • As per Muhammad Umer's answer, I used .replace() instead of .add() .. It now reloads/refreshes the Fragment . – Gissipi_453 Oct 02 '15 at 12:11

1 Answers1

1

Use .replace() instead of .add().

Muhammad Umer
  • 70
  • 1
  • 13