3

I need your help.

I have one Activity with two fragments: one fragment with simple TextView in LinearLayout and other fragment: ViewPager with 3 fragments in FragmentPagerAdapter.

I make transaction with replace action, but I have error from ViewPager: java.lang.IllegalStateException: Recursive entry to executePendingTransactions.

That's a source code that show this problem, maybe anybody knows how to fix it.

Maxim Yudin
  • 1,631
  • 13
  • 13
  • I decided this problem by other manner. In my case I create TabHost with 2 activity, then in first activity I put ViewPager with 3 fragments and in second fragment I put simply fragment with text. – Maxim Yudin Aug 31 '11 at 12:48
  • for nested fragments you need to pass `getChildFragmentManager()` in the constructor of your `FragmentPagerAdapter/FragmentStatePagerAdapter` – Muhammad Babar Nov 11 '14 at 07:02

3 Answers3

2

With revision 11 of the Android Support Library, you can now nest fragments within fragments to avoid the recursive exception. See this question How to add a Fragment inside a ViewPager using Nested Fragment (Android 4.2)

Community
  • 1
  • 1
Marco RS
  • 8,145
  • 3
  • 37
  • 45
2

Um no. A ViewPager extends ViewGroup. How does that make it a Fragment?

Yes, you're right that nesting Fragments isn't supported. However, it works if you have a Fragment holding a ViewPager whose Adapter contains several Fragments. Trust me, it works. I'm using it in the current project I'm working on right now and I've even got nested ViewPagers without the horizontal touch events fighting for control, so essentially I have Fragments within a Fragment.

Android Noob
  • 3,271
  • 4
  • 34
  • 60
  • I attempted to do exactly what you describe and got the error shown in the question. Can you possibly show us how you accomplished this? – howettl Oct 08 '11 at 19:01
  • 3
    If anybody is interested, a working solution can be found here: http://stackoverflow.com/questions/7700226/display-fragment-viewpager-within-a-fragment/7700305#7700305 – howettl Oct 08 '11 at 23:22
-13

A ViewPager is basically a Fragment, and you can't put Fragments in Fragments. Period.

Tyler
  • 84
  • 4