Building a Fragment pager/slider app
We can put complete Fragments as pages in PagerAdapter
. This is quite powerful because as we know, a Fragment can have a lot of functionality, even a full-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 TextView
, however, it should be clear as to how we could easily add any layout that we have learned about so far and then let the user interact with it.
The first thing we will do is build the content for the slider. In this case, of course, the content is Fragment
. We will build one simple class called SimpleFragment
and one really simple layout called fragment_layout
.
This implies that each slide will be identical in appearance, but we will use the Fragment
ID passed in by FragmentManager
at the instantiation as the text for the one and only TextView
. This way, when we flip/swipe through Fragments...