Let me describe my project.
I use actionbarsherlock with SlidingMeno from jfeinstein10 . On my main activity i have this sliding menu with a couple of menu item that open Fragments in container. (the same as basic fragment sample in sliding menu example) In one of those fragments i have view-pager with viewpageindicator. View-pager is tied up to FragmentStatePagerAdapter with my fragments. So i have fragments inside fragments. I use getChildFragmentManager() like suggested in the doc, when using fragments inside fragments.
When i select menu item with fragment that hold view-pager for the first time everything work like it should. But when i select some other menu item and then go back to this view-pager fragment i get this exception.
All other fragments don’t have this problem and in stack trace there is no reference to my code.
https://gist.github.com/4502038
Did any one encounter similar problem or have some idea what is going on.
EDIT: If i use getFragmentManager() instead of getChildFragmentManager() even thou i'm in subfragment. I don't get an exception, but one of the fragments inside viewpager doesn't get recreated after i select viewpager fragment for the second time.
I created a project on github so you guys can take a look.
https://github.com/pzagor2/TestErrorApp
See this: https://code.google.com/p/android/issues/detail?id=42601 bug.
Uncommenting addToBackStack https://github.com/pzagor2/TestErrorApp/blob/master/MainActivity/src/com/example/myapp/MainActivity.java#L69 , worked for me with your project setup.
You can see the bug in the Google bug report in the first URL.
Hope this helped.
I just looked at the GitHub project and it looks like you have not commited your code yet. But I assume your ViewPager is in a fragment itself and the ViewPager is hosting child fragments. If that's so, then I would recommend you test to make sure your FragmentStatePagerAdapter is constructed with the result of getChildFragmentManager().
Related
I am developping an app with an activity which switches between a few fragments. I was wondering if it is possible to have one of this fragment with tabs in the action bar, but not the other ones, knowing that, in general, the activity is tabbed and the tabs switch between fragments.
In a nutshell, I want an activity with a few fragments, and one of this fragments should have tabs to browse between other fragments, is that possible?
Ofcourse it is possible, take a look around StackOverflow, there are a couple of questions already.
Instead of normal TabHost your should use FragmentTabHost and because you will have fragments inside a fragment, you will have to use getChildFragmentManager() instead of getFragmentManager().
Adding tab inside fragment
Nice post Marko! I was just typing up basically the same answer. Here is a link for the documentation on Nested Fragments hope that helps as well
I’m trying to do a tab layout, but before I’ve a navigation drawer that contains some menu. In one of those items I want to display a Tab activity or let’s say view. My problem is in the replace method we should pass a Fragment and in a tabbed view you can't do it with a Fragment you should have an activity or a FragmentActiviy. Now I’m trying to found a solution to this.
There is nothing that actually forbids using a ViewPager inside a Fragment, but I'd try to avoid going down that road. I fear for the UX, having both a navigation drawer and tab navigation is very confusing.
If you must do it nonetheless, you can find an example of using ViewPager on the official documentation page here, it is using Activity but the only main difference I see when implementing that in a Fragment is that the FragmentManager you use should be the one obtained calling getChildFragmentManager inside the main Fragment.
I am using Fragment for Slider menu in Android. Source : Android Slider Menu
Now, I want to add ViewPager inside first Fragment which is Home. So I found some tutorials for it. But all are using FragmentActivity so I am not able to call it inside Fragment.
Please help me regarding this.
I think this should help you out.The key is to use Nested Fragment calls instead of a calling an Activity that uses the FragmentActivity.Find more about Nested Fragment calls here Please check out this question and see how this is implemented.
Android: Viewpager inside a fragment of Navigation Drawer
I know my questions sounds like a tongue twister. Anyway I wanted to implement it but I don't have any idea on how to do it. I already know on how to use a FragmentActivity and add the TabHost for it but now what I have is a fragment that should also contain a Tab which also has a fragment. To give it a more detail here's what I wanted to implement:
What I tried so far is to Create a new FragmentActivity which will be contained inside a FragmentActivity and I got a ClassCastException. Any ideas on how can I achieve this?
Using a newer version of the Support Library, or native Fragments if you only care about Honeycomb, you can add Fragments as children of other fragments.
You can call getChildFragmentmanager() inside one of your top level Fragments and add your child Fragments there.
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.
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.
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)
A ViewPager is basically a Fragment, and you can't put Fragments in Fragments. Period.