Building a Fragment Pager/slider app
We can put whole fragments as pages in a PagerAdapter
. This is quite powerful because, as we know, a Fragment
can have a large amount of functionality, even a fully-fledged UI.
To keep the code short and straightforward, we will add a single TextView
to each Fragment
layout, just to demonstrate that the pager is working. When we see how easy it is to get a reference to the TextView,
however, it should be obvious how we could easily add any layout we have learned so far and then let the user interact with it.
Note
In the next project, we will see yet another way to display multiple Fragment
instances, NavigationView
, and we will actually implement multiple coded Fragment
instances.
The first thing we will do is build the content for the slider. In this case, of course, the content is Fragment
s. We will build one simple class called SimpleFragment,
and one simple layout called fragment_layout
.
You might think this implies that each slide will be identical...