October 2018
Intermediate to advanced
464 pages
15h 17m
English
The first step is to create a fragment. Since we're doing a slideshow, all we need is ImageViewer. We also change MainActivity to extend FragmentActivity to load the fragments into ViewPager.
ViewPager uses FragmentStatePagerAdapter as the source for the fragments to transition. We create SlideAdapter to handle the two callbacks from the FragmentStatePagerAdapter class:
Furthermore, getCount() simply returns the number of pages we have in our slideshow, and getItem() returns the actual fragment to display. This is where we specify the image we want to display. As you can see, it would be very easy to add to or change the slideshow.
Handling the Backspace key isn't a requirement for ViewPager, but it ...