Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Android Application Development

You're reading from   Learning Android Application Development Start building for the world's most popular mobile platform

Arrow left icon
Product type Paperback
Published in Aug 2016
Publisher Packt
ISBN-13 9781785286117
Length 320 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Raimon Ràfols Montane Raimon Ràfols Montane
Author Profile Icon Raimon Ràfols Montane
Raimon Ràfols Montane
Laurence Dawson Laurence Dawson
Author Profile Icon Laurence Dawson
Laurence Dawson
Arrow right icon
View More author details
Toc

Creating fragments

As with activities, now that we have covered the same old dry introduction to fragments, we can actually begin to use them! In the following sections, we will cover how to create fragments, create a static Fragment constructor, and instantiate a fragment that binds one or several fragments into a single parent activity.

Creating our own fragment

As we did in the activity example, perform the following steps:

  1. Open the Project tab on the right-hand side of the screen.
  2. Right-click on the com.example folder.
  3. Go to NewJava Class and name the class SampleFragment.

As all custom activities extend the class Activity, all custom fragments extend the class Fragment.

Note

If you are using the support library, you can choose to either use the Fragment class built into Android as of Honeycomb (API v11) or the android.support.v4.app.Fragment class bundled as part of the support library. If you are planning on supporting devices pre-ICS (API v14), you must...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image