Skip to content Skip to sidebar Skip to footer

Fragment Shows Twice On Top Of Eachother

I im displaying fragments in my activity, but seems that some fragments are displaying(instatiating) twice. I'm double checking my code but and in my opinion all should be ok. The

Solution 1:

First make your view static,then paste the code in onCreateView in fragment.

privatestatic View view=null;

if (view == null) {
            view = inflater.inflate(R.layout.fragment_movies, container, false);

            //code here for first time initialization
        } elseif (view != null) {
            //your code here
        }

Solution 2:

If you use the code you posted to switch from one fragment to another, I would say it may come from how you get the Fragment you pass to your showFragment() method. If you create a new Fragment before passing it to showFragment(), it is normal that a new fragment is created and added on top of the others.

you should use getFragmentManager().findFragmentByTag(String Tag) to get a fragment already in place and re-add it on top of the Fragment stack.

Post a Comment for "Fragment Shows Twice On Top Of Eachother"