Page 138

Android Programming Cookbook

130 / 143

Chapter 8

Android ViewPager Example One of the most popular views in Android is the ViewPager, a view that helps us slide from one "screen" to another like a "slideshow". Android ViewPager view can be found in many cases, in tutorial or introductory screens, on tab views and galleries. We are going to create an AppCompatActivity, and we are going to add a ViewPager reference and in it, as well as a FragmentPagerAdapter that will help us navigate between the Fragments that our ViewPager will consist of and that we are going to create. Then, we are going to make instances of Fragments that will be added in our Adapter. The Android ViewPager has default swipe-gestures from one "screen" to another, and we do not need to create any gestures in order to transit between the pages. So, in this example, we are going to show, how we can implement an Android ViewPager. Let’s start. For our example will use the following tools in a Windows 64-bit or an OS X platform: • JDK 1.7 • Android Studio 1.3.2 • Android SDK 6.0 Let’s take a closer look:

8.1

Create a New Android Studio Project

Open Android Studio and choose Start a new Android Studio Project in the welcome screen.

SKY MAGZ  

This is Yahya Christian School Magazine