Fragments can also be used with the ViewPager component - a container that lets the user swipe from side to side to navigate a data set. Each instance of a fragment represents a page. The ViewPager manages the creation of pages, and passes data to each page as it's needed. All you need to do is create the fragment and its layout, and then wrap the fragment with the ViewPager component.
- [Voiceover] A ViewPager component allows the user to…swipe though a data set,…seeing one data element at a time.…It's essentially an alternative to a list view,…but it let's each item occupy the entire screen…or some portion of the screen as a fragment.…In order to create the pages in a ViewPager…you start with a fragment.…The fragment looks just like fragments…that use in other ways,…either as parts of activities or in dialogues.…So if you've been following along in this course…the process of creating the fragment itself…will look familiar.…
In this project ViewPagerFragment,…I'm starting with a static data set.…There are a number of products…each with four values,…a product ID, a name,…a description, and a price.…Those are represented in this Java class named Product…with private fields and getters.…There is also a constructor here that is used in…the data provider class.…My goal is to create a ViewPager component that…allows the user to see one product at a time.…
I'll be creating the product…and passing it to a fragment.…
Author
Released
9/1/2016- Configuring Android Studio
- Understanding fragments
- Creating a fragment class and layout
- Adding and removing fragments with Java
- Creating layouts for multiple screens
- Understanding arguments and callback methods
- Passing arguments to a fragment
- Choosing layout at runtime
- Displaying dialogs with fragments
- Using fragments for managing dialogs, shared preferences, and more
Skill Level Intermediate
Duration
Views
-
Introduction
-
Welcome1m 4s
-
What you should know1m 50s
-
Using the exercise files1m 39s
-
-
1. Getting Started
-
Understanding fragments3m 17s
-
2. Display Fragments in Activities
-
Display a fragment with XML3m 16s
-
Add a fragment with Java3m 50s
-
3. Manage Fragments at Runtime
-
Pass arguments to a fragment5m 18s
-
Choose layout at runtime3m 21s
-
-
4. Communication between Fragments and Activities
-
5. Display Dialogs with Fragments
-
Display a custom dialog5m 1s
-
Pass arguments to the dialog4m 16s
-
6. Other Uses of Fragments
-
Create a ViewPager adapter4m 53s
-
Conclusion
-
Next steps1m 11s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Create a fragment for ViewPager