Android: FragmentActivity inside FragmentActivity (ScrollView in NavigationBar) - android

I have a FragmentActivity which can swipe through several fragments via ViewPager and a FragmentActivity which hosts an ActionBar for navigation.
Now I want to nest the FragmentActivity with the ViewPager in the first fragment of the other FragmentActivity which hosts the ActionBar.
In other words I like to have an ActionBar navigation and in it's first Tab I'd like to have swipeable fragments.
My problem is how to nest one FragmentActivity in another FragmentActivity. Both work on their own but I don't get them to work together.

Swipe Gesture applied at Fragment level along with ViewPager with it's default swipe disabled
You can write your own touch interceptor for the fragments inside your view-pager.
However on a second opinion, please see my moqup in the question:
You can have several ViewGroup container preferably FrameLayout, where on each you can add or remove fragments using transactions. The container of the Navigation Panel is different than where the ViewPager is showing:
Keep this ViewPager in a separate fragment that spawns in yet another FrameLayout. in ViewPager here you should not use the FragmentPageAdapter, but a regular PagerAdapter (avoid nesting of fragments). Hence the ViewPager is a parent container for the Views, and not Fragments where they are shown.
The target of the navigation drawer (on item click) will be this second FrameLayout. Keep it simple!!
Similarly you can have a ViewPager inside a first tab of Tab based ViewPager with this new found information.

Related

Replace fragment in tablayout

I have a parent fragment containing TabLayout and ViewPager.
The TabLayout has 3 tabs (fragments) managed by FragmentStatePagerAdapter.
After the user clicks on a button on the 3 fragment, I would like to replace it with different fragment, without reloading the parent fragment.
I tried to remove the fragment and add the new one and call notifyDataSetChanged() and the fragment is indeed replaced, but the TabLayout custom view headers are gone...
Any idea how can I do it right?
Thanks.
You can have the 3rd Fragment working as a holder for two child Fragments which you can switch based on your app's logic (clicking the button you mention).
The key for this alternative is that the 3rd Fragment in the ViewPager will be the parent of the two Fragments that will be switching.
The two child Fragments will communicate with the parent Fragment for the parent to take care of doing the switching.
For the switching the parent will use a ChildFragmentManager instead of the FragmentManager used for Fragments that are managed by Activities.

2 fragments displayed dynamically in one tab of application

I build an application which has tabs in it, and using ViewPager to swipe between the tabs.
Is it possible that one tab will show firstFragment, and then when pressing a Button will show firstFragment and secondFragment?
Of coarse you can. When you bind ViewPager to TabLayout you use adapter, which extends FragmentPagerAdapter, that adapter stores list of all fragments and layout texts. Just replace fragment in it and invalidate result.
But, this should by done from Activity, which has ViewPager and TabLayout.
Define interface in your first program, implement it in Activity and replace fragment on button click.

Regarding to the contradiction of using ViewPager

My question is in my activity or fragment, there are TabLayout and ViewPager. If I was to disable swipe of ViewPager by using a class called NonSwipeableViewPager. Then why should I bother to using ViewPager right from the start, I could have just use TabLayout to add tabs which is much more simpler.
What are the other advantages of using ViewPager even though the primary function of it which is Creating Swipe Views with Tabs is not needed?
Do Fragment layout must use framelayout? Which means can I use relative or liner layout instead of framelayout?
Last but not least, do I allowed to use ViewPager with the swipe disabled?

Nested Fragments - communication between child fragments in a parent fragment in a viewpager

I'm working on the initial design of an app here and I've run into some issues with how I'd like things to work.
Some background to start:
The app is using ActionBarSherlock for the overall UI. It's a tabbed design which uses a ViewPager along with a FragmentStatePagerAdapter to swap between the different tabs(which are SherlockFragments).
One tab in particular is a master-detail style SherlockFragment which contains and displays two nested fragments, a SherlockListFragment(the master) and a regular SherlockFragment(the detail).
All the examples I've seen on how to create a master/detail with fragments show the list communicating with the detail via an interface callback which is then implemented in the FragmentActivity that the master/detail fragments are attached to.
In my case though there is no FragmentActivity, the two Fragments are inside a parent SherlockFragment. How can I get the listFragments onItemSelected to update the detailFragment? Is it possible to set up an interface callback between two Fragments directly(or through the parent Fragment) without involving a FragmentActivity?

Add FragmentActivity inside a tab on Android ActionBar tab.

I have a tab bar view created using FragmentActivity. I also have separate sliding ViewPager, created using FragmentActivity. I just need to add this sliding ViewPager inside one of the tab on the my tab bar view. Basically I need to have sliding view inside one of the tab (not the swipe view with tab). I am using Android 4.0 and above.
Can anyone please help me on this ?
This is not possible. You cannot "Add FragmentActivity inside a tab on Android ActionBar tab". Activities-inside-of-activities has been deprecated for ~30 months and never supported action bar tabs.
One possible alternative is for you to change your ViewPager to be inside a Fragment, instead of a FragmentActivity. If the ViewPager is using a fragment-based PagerAdapter, it can do so using nested fragments -- use getChildFragmentManager() when creating your PagerAdapter. Here is a sample project demonstrating a ViewPager in a fragment and using nested fragment for pages.

Categories

Resources