The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
As we saw at the outset, there will be three main elements of the user interface when we are done:
We could implement all of those as activities, if we wanted to. However, that will make it difficult to implement a good UI on a tablet-sized device. Each one of those three elements is much too small to be worth taking up an entire 10" tablet screen, for example. So, while we will show one of those elements at a time on smaller screens, on larger screens we will show two at a time:
We cannot do this with three independent activities. This is where fragments come into play. We can define each of the three elements as a fragment, then arrange to show either one or two fragments at a time, based upon screen size.
In this chapter, we will convert our existing list into a fragment and have our activity display that fragment. This will have no immediate impact upon the user experience — the app will be unchanged visibly as a result of these changes. But, we will be setting ourselves up for creating the other two elements — a details fragment and an edit fragment — in later tutorials. And while we will focus on smaller-screen devices now, in a later tutorial we can adapt our app to show two fragments at a time on larger-screen devices.
This is a continuation of the work we did in the previous tutorial. The book’s GitHub repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.
This tutorial assumes that you have learned the basics of working with fragments from somewhere. That could be:
The preview of this section is in an invisible, microscopic font.
The preview of this section is sleeping in.
The preview of this section was lost due to a rupture in the space-time continuum.
The preview of this section was abducted by space aliens.
The preview of this section apparently resembled a Pokémon.
The preview of this section took that left turn at Albuquerque.