Create your account

Already have an account? Login here

Create account

51. Adding a Fragment to XML

Design + Code an Android App from Scratch

Woah, wait a second..

Scrounge up some loose change to become a pro member, or login to your account to view this lesson.

Alright, join now. Or login to your account if you're already a pro member.

This video shows how to add a Fragment to XML directly. In the first step, create an activity and its layout file. Create a class that extends the android.app.Fragment or android.support.v4.Fragment and override the onCreateView method. Define a layout for the fragment that contains all the UI widgets which you want to display inside the Fragment. Link this layout inside onCreateView using a Layout Inflater. Create the fragment tag in the XML layout of the Activity and specify the class attribute to point to the Java class file of the Fragment that you created earlier.

Course Cirriculum