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().
Related
I am using a Navigation Drawer Activity inside that I have let say xyz Fragment , inside xyz fragment I have FragmentTabHost . Now I want to change Fragment in FragmentTabHost onClick on a button from a fragment in FragmentTabHost.
You should check this code
Which is part of the official google sample for using a Navigation Drawer with Fragments project.
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
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 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.
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)