Search code examples
androidandroid-fragmentsandroid-viewpagernavigation-drawerandroid-tablayout

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:

  1. Mainactivity.java - https://gist.github.com/Faizi-alpha/c03df8bc9795c10e3c97d68d9f82c6cb
  2. Fragment_Department.java - https://gist.github.com/Faizi-alpha/e166f914727af88fb70e084f67f80fa5
  3. 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 ??


Solution

  • Use getChildFragmentManager() instead of getSupportFragmentManager().