1

I have a Fragment which contains a ListView say FragmentA, when I add another Fragment which contains another ListView say FragmentB:

getFragmentManager().beginTransaction()
    .add(R.id.fragment_container, FragmentB)
    .commit()

I noticed that getView() of ListView in FragmentA is still getting called even though the top fragment is now FragmentB, any reason why and how do I prevent this behavior?

Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
Andreas Wong
  • 59,630
  • 19
  • 106
  • 123

1 Answers1

3

You're stacking fragments on top of each other.

Instead of add use replace to replace any existing fragments in that container.

Simas
  • 43,548
  • 10
  • 88
  • 116