Second set of tabs in an Android fragment - android

I want to add a second row of tabs to my Android application on the second fragment accessed from the ActionBar tabs.
Tab 1 shows fragment 1.
Tab 2 shows fragment 2 but I would like fragment 2 to have a second row of tabs so it will show fragment a or b.
But it seems like fragments within fragments cannot be done and an ActionBar submenu can't be switched on or off. I have also tried with a FragmentStatePagerAdapter with a TabHost and a ViewPager which displays the tabs fine but does not display the fragments. Is there any other way to do this?

If you know the new Design Support Library ....
In your second fragment you can use TabLayout introduced in design support library 22 . Which is same as Actionbar tabs.
So just add the TabLayout in your second fragment XML.
And TabLayout has a method setUpWithViewPager(). So you can easily setup your tabs.
I hope it helps you.
here is the reference http://android-developers.blogspot.in/2015/05/android-design-support-library.html

Related

Android TabLayout inside NavigationDrawer with Fragments

I am using NavigationDrawer with Fragments. Now I have 8 menu's in my navigation Drawer but I want to use tab layout in only two or 3 fragments.
Navigation_Menu Image
I am using tab layout in a fragment whose name in the menu is department.
So I am using ViewPager and PagerAdaper so do I need to write the code in Main Activity or fragmentClass.java
I was having trouble using Code Snippet on Stack Overflow so here are the gist's of my code:
Mainactivity.java -
https://gist.github.com/Faizi-alpha/c03df8bc9795c10e3c97d68d9f82c6cb
Fragment_Department.java -
https://gist.github.com/Faizi-alpha/e166f914727af88fb70e084f67f80fa5
FragmentDepartmentView.xml - https://gist.github.com/Faizi-alpha/238386596515661bd00043b61966220a
Where Should I write the Java PagerAdapter and ViewPager code? I tried coding it in DepartmentFragment.java but I am not getting "getSupportFragmentManager()" in this class.
Do I need to handle each fragment in mainActivity.java ??
Use getChildFragmentManager() instead of getSupportFragmentManager().

Best practices for multiple layouts with fullscreen view, tabs and toolbar

I would like to make a layout that it would be something like this:
A login layout with no toolbar or title bar
A select action layout with toolbar and no tabs
Another layout with toolbar and 3 tabs
and im thinking on how to implement this, how many fragments, activities etc.
I was thinking of having 1 activity full screen and another activity with fragments, toolbar and tab and every time i want a layut with tabs to remove the tabs and in the next screen to add again the tabs.
But after thinking it out it seems like a bad idea.
Should i create a seperate activity with fragments and tabs and navigate around those 3 layouts?
What is the best approach when you want to use tabs and a toolbar but you dont want in all your layouts to have tabs?
You only need 1 Activityand 3 Fragments. In the fragments where you need a toolbar, just use Toolbar view. This is available on Support Library so you will not have problems with older Android versions.
And in the Fragment with the tabs, just use a TabLayout and a ViewPager in order to switch between tabs (each tab is a Fragment).

Material design sliding tabs not accessing more than two fragments

I have designed material design sliding tabs in android. I have added 3 tabs and want to change the UI at runtime from main activity but only 2 fragments has been instantiated and accessed except the 3rd. how to get the 3rd fragment to be instantiated and accessed?
By default the offscreenPageLimit for the ViewPager is 1. so, the ViewPager loads and extra one page from left and one page from right (total 3 pages).
You can change that by calling ViewPager.setOffscreenPageLimit(2);
this will load a 2 pages from each side (total 5 pages).
Refer this
Implement Sliding Tab Layout

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.

Making one of the actionBar tabs have a view pager

I am trying to make an app to do the following function:
I need to have an ActionBar with 3 tabs such that one of the tabs has to implement a ViewPager and the other 2 tabs has to have separate layouts.Although I know how to create an ActionBar with Tabs with fragments, I am not sure how to(or if it is even possible) to implement a ViewPager inside one of the tabs.Thanks a lot for your help.
Edit:Nvm I found the solution.You have to use nested fragments.For more information refer to
How to add a Fragment inside a ViewPager using Nested Fragment (Android 4.2)

Categories

Resources