简体   繁体   中英

Android - add Swipe View/tabs to only SOME fragments

Currently, my app is using a navigation drawer for my fragments. However, I have 2 fragments that are related, I would like to put these under one heading on the navigation drawer and then have 2 tabs to switch between the related fragments once I select that choice on the drawer.

Is this possible with only one activity or would I have to implement another activity specifically for the tab? I've considered only adding the tabs once the right fragment is committed but that leaves the question of how to remove it once I switch to a fragment that doesn't require the tabs.

I'd also like to avoid having to implement another activity as I am trying to keep the navigation available through my whole app. I'd rather not have to create an identical drawer and then have to keep things consistent between the 2 drawers.

Edit: So far, I've managed to make a parent fragment that has a viewpager, fragmentpageradapter, and tablayout. Swiping between the 2 tabs does indeed shift between my 2 desired child fragments. However, I am unable to change a textview in one of my child fragments from my MainActivity. I'm guessing the reason why this is the case is because technically, my parent fragment is in view, not my child fragment. Any suggestions to get around this?

Hierarchy:

MainActivity

-Navigation Drawer

--Fragment1

--Fragment2

--Fragment3

--Fragment4

---FragmentPagerAdapter (under Fragment4, tabs)

----SubFrag1

----SubFrag2

Here's how you might use FragmentStatePagerAdapter to swipe across a Fragment:

http://developer.android.com/intl/es/training/implementing-navigation/lateral.html

I hope it help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM