Chapter 11. Dynamic Fragments: Nesting Fragments
So far you’ve seen how to create and use static fragments. But what if you want your fragments to be more dynamic? Dynamic fragments have a lot in common with dynamic activities, but there are crucial differences you need to be able to deal with. In this chapter you’ll see how to convert dynamic activities into working dynamic fragments. You’ll find out how to use fragment transactions to help maintain your fragment state. Finally, you’ll discover how to nest one fragment inside another, and how the child fragment manager helps you control unruly back stack behavior.
Adding dynamic fragments
In Chapter 9 and Chapter 10, you saw how to create fragments, how to include them in activities, and how to connect them together. To do this, we created a list fragment displaying a list of workouts, and a fragment displaying details of a single workout.
These fragments we’ve created so far have both been static. Once the fragments are displayed, their contents don’t change. We may completely replace the fragment that’s displayed with a new instance, but we can’t update the contents of the fragment itself.
In this chapter we’re going to look at how you deal with a fragment that’s more dynamic. By this, we mean a fragment whose views gets updated after the fragment is displayed. To learn how to do, we’re going to change the stopwatch activity we created ...
Get Head First Android Development, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.