The first step in learning how to use…the fragments API is creating a fragment.…To create a fragment, you'll need…an XML layout file and a java class.…I'm working in the project create fragment…from chapter two of the exercise files.…In this project, there's an XML layout…file called activity main dot XML.…Its root element is a relative layout…and it contains a single text view.…The text view is displaying the text "hello world"…which is actually a string resource.…
To create a fragment, I'm just going…to make a copy of this XML layout file.…In the project view, I'll right click on the XML file…and I'll copy it to the clipboard, and then I'll right click…on the layout folder and paste it in to place.…I'll name the new file my fragment.…The XML content for the fragment layout file,…right now, it's exactly the same as the activity.…This is to emphasize the point.…A fragment can do everything…that an activity can do visually.…
But to make sure I know when I'm actually…seeing the fragment, I'll change the text…that the text view is displaying.…
Author
Released
8/21/2014- Understanding fragments
- Adding fragments to activities
- Creating layouts for multiple screens
- Understanding arguments and callback methods
- Updating apps with support for fragments
Skill Level Intermediate
Duration
Views
Related Courses
-
Introduction
-
Welcome1m 12s
-
Using the exercise files4m 3s
-
-
1. Getting Started
-
Understanding fragments3m 5s
-
2. Adding Fragments to Activities
-
Using a List fragment5m 34s
-
3. Creating Layouts for Multiple Screens
-
Using resource aliases6m 41s
-
4. Communicating between Activities and Fragments
-
5. Using Fragments in Gingerbread and Froyo
-
6. Other Uses of Fragments
-
Using preference fragments10m 13s
-
-
Conclusion
-
Next steps1m 27s
-
- 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: Defining a fragment layout in XML