简体   繁体   中英

Navigation with ActionBar Tabs & nested fragments

If you are using an Actionbar with Tabs for navigation, should we be using fragments only? When I'm looking at the developer site, I only see examples where they are switching Fragments, not Activities. The guidelines tell us to use a ViewPager when using tabs, so you should use Fragments to make that work.

The problem is that these fragments will contain quite a lot. They should have other fragments as well. Nested fragments. These are supported when using the Support Library (or targetting api level 17).

My main concern is how the communication will run between the fragments at the bottom of the hierarchy. Will it all run through that one Activity?

You won't have problems. Just treat your fragments as something independent that will be placed in a container. That fragment can have more fragments and so on.

Some people are developing fragment based applications with a single Activity and sometimes makes sense, however I don't like that approach much.

That said, just use all the fragments you need. If you have complex data to pass between fragments you could use the activity to host it and access it in your fragments.

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