Munish Kapoor Munish Kapoor - 1 year ago 171
Android Question

Android ViewPager Inside Fragment Loaded Only Once

I am getting issue with ViewPager. I am using FragmentActivity and I added the multiple fragment inside FragmentActivity as following method.

public void addFragment(Fragment fragment, boolean addToBackStack, int transition) {
FragmentTransaction ft = getFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_up,R.anim.slide_down,R.anim.slide_up,R.anim.slide_down);
ft.replace(, fragment);
if (addToBackStack)


I am using ViewPager Inside the fragment. ViewPager is working fine when FragmentActivity loaded. but when i use another fragment ViewPager got invisible.

for example

a.) Fragment A with ViewPager

b.) Fragment B without ViewPager

Fragment A working fine when I run App. when i go to Fragment B
then I again i replace Fragment B to Fragment A then ViewPager is not working. I see the blank view where I am using ViewPager.

Please let me know How can i solve this issue


Answer Source

I solved it myself the issue was when you use the ViewPager inside the fragment use getChildFragmentManager() instead of getSupportFragmentManager() or getFragmentManager().

That's it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download