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.
Related
I followed the following tutorial to create an app with a material design tabbed interface with the result here.
My question is that in my TAB3 (a fragment) I have a Spinner at the top to change between 2 types of data view, a ListView and a TableView (diary).
I am a complete beginner programmer and I am not sure how to implement this. I have searched and know I cannot create a Fragment within a Fragment. I was thinking of communicating from the TAB3 Fragment to the parent Activity (though I'm not sure if this should be the MainActivity or the ViewPagerAdaptor) via an interface to swap out the TAB3 fragment to another one when selected with FragmentManager. Or is there a way I'm missing to swap out the ListView to a TableLayout on the fly within the Fragment?
I have searched much on this with my limited understanding and most tutorials can explain how to communicate from an activity to a fragment or fragment to fragment, but my situation seems a bit different in that all this exists within the TAB3 fragment and I don't know how to switch out a portion of that fragment.
If I understand you correctly, just make fragment in tab 3 as container and use nested fragments.
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 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.
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.
I have gotten my tabs up and running with Sherlock Fragments. So i have two tabs and two fragments. Now what i want is that when i click on a button in one of the fragments, I want another fragment to open up, but it should be inside the tab that contained the original fragment. Can anyone show me how this can be done ?
Actually Nested Fragments are not possible directly. I had a similar issue and but the Fragment to be shown was small and simple. So I just played with setVisibility() as LinearLayout.GONE and LinearLayout.VISIBLE
On the Fragment initialization, I hid the second layout and when I need to show the other fragment, I hid the first layout and showed the second layout. It worked great for me!