Control two fragments within a tab - android

I was hoping someone could point me in the right direction when using fragments within a tab. I have a mutiple tab application. On one of the tab pages I have broken down the content into two separate fragments.
The issue is I do not want the fragment activity I using to control the tab to control also control the two fragments being displayed. I want an something between the two elements such as another fragmentactivity to control the fragments used as content.
Is this possible and if so how?
Tab Fragment
tab 1 tab2 tab 3
tab2 : display is two fragments
tab2 -> anther fragmentActivity -> two displayFragments

Transition to FragmentActivity
I believe I've found my answer. This can't be done. My fragments need to response to a fragmentActivity and the fragmentTransaction only transitions between fragments not activities. So they will have to respond to my activity controlling the tabs.

Related

Does the backstack only exist in the FragmentManager instance?

So if for example I had 4 fragment managers, would there be 4 seperate back stacks to handle?
Im looking to create a tabbed application that uses a bottom nav bar to switch between fragments. But within each tab the user can progress through to different areas of the app. I need it so that no matter how far they get in to a tabs flow, if they clicked on another tab, then came back to the previous tab, they would still be at the same place they left off.
So would using multiple FragmentManager instances (one for each tab) solve my issue?
In my case I have 4 fragments, one for each tab. So if im on tab 1 and go to fragment 4 in tab 1, if I then tap tab 3 and go to fragment 2 in tab 3, if i then go back to tab 1, i should still see fragment 4 of tab 1. But im not sure how to set this up.
You should be fine using two Fragment instances for the tabs in the nav bar, and use each tab Fragment's getChildFragmentManager() method

Android ViewPager with Fragments

I have an App using ViewPager which has 3 tabs. I need each tab to contain a navigation stack of fragments e.g. I have a list on the first fragment which will then display a detail fragment based on clicking an item. What is the best way to design this? At the moment, I have one MainActivity which replaces the Fragments within each tab but as I'm adding more fragments within each tab, the MainActivity will just become huge. Can I handle all of this within the fragments themselves?
I think what you are looking for is a tabhost with backstack. This makes use of a TabHost, and is not the same as using a ViewPager with tabs. But that solution on Github is a very good one.
Also, this will not make your MainActivity "huge", because all the Fragments can be defined as separate classes in their own class files. Fragments are supposed to represent more modular UI blocks.

Swiping fragments in fragment

Can anyone tell me, how to make a tab viewer with fragments? Something like in image:
Activity, which contains two fragments, one of the fragments contains tabs with two fragments.

Use fragments or activities inside a tab navigation?

I have an app with 4 main tab fragments. However, inside each tab, the user can do different actions which brings him to navigate inside that same tab. Should I launch new activities or just replace the tab fragment with new fragments? The big downside I see of using new activities is I lose the tab navigation view.
What should I do? Use only fragments? That's a lot of fragments for one activity.
Use fragments. They fit your situation perfectly. And don't worry, 4 fragments inside one activity is not too much. Fragments are designed to be lightweight, so you can use even more.

Is there a way to display fragments in TabHost?

I'd like to show a different fragment in a TabHost, for every tab. But
it seems that there's no easy way to do this. TabHost can only accept
A. Views or B. Intents that launch Activities when the user selects a
tab.
Going with A means that I have to initialize every fragment and load
them into container Views that are given to the TabHost. But I want
these fragments to load only when needed - when the user selects their
tab that is.
Going with B means that I load the fragments into separate Activities
for each tab. But I'd like the fragment to be able to reach the
"original" parent Activity, not just some shell Activity that hosts
them in a tab content.
Am I missing something? Is there a way to manage fragments with
TabHost properly?
Some hits here:
fragment Support with Tabhost
Android 1.6 & Fragment & Tabhost
For what I understood, "link" a fragment inside a TabHost isn't allowed, you need to create activities that include your fragments and then call these activities from TabHost.
EDIT
the "official solution" from Google, and with nice animations.

Categories

Resources