Join David Gassner for an in-depth discussion in this video Adding a fragment to an activity with XML, part of Building Adaptive Android Apps with Fragments.
Once you've created an XML layout file,…and a java class that manages a fragment…you're ready to add the fragment to an activity…and you can do this either with XML markup…or with java code.…I'll show you how to do it in XML first.…I'm working on a project named add fragment XML.…And it continues from where the last one finished.…It has two layout files, activity main,…which is currently being displayed, and my fragment.…Which has the same sort of code, but displays…the text hello from a fragment.…
I'll go back to the main activity and I'll remove…this text view widget.…The preview pane over on the right now shows…the app with a blank screen and I'm going to…replace that with the fragment tag.…Start by typing an opening tag and then fr for fragment,…and then select fragment.…When you select the fragment tag, Android Studio…automatically adds the required layout width…and layout height attributes.…Set both of those to feel parent.…
And then finish the tag with the empty tag syntax.…We're not done yet.…There are a couple of other required attributes.…
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
Share this video
Embed this video
Video: Adding a fragment to an activity with XML