Book Image

Learning Android Application Development

By : Raimon Ràfols Montane, Laurence Dawson
Book Image

Learning Android Application Development

By: Raimon Ràfols Montane, Laurence Dawson

Overview of this book

The mobile app market is huge. But where do you start? And how you can deliver something that takes Google Play by storm? This guide is the perfect route into Android app development – while it’s easy for new apps to sink without a trace, we’ll give you the best chance of success with practical and actionable guidance that will unlock your creativity and help you put the principles of Android development into practice. From the fundamentals and getting your project started to publishing your app to a huge market of potential customers, follow this guide to become a confident, creative and reliable mobile developer. Get to grips with new components in Android 7 such as RecyclerView, and find out how to take advantage of automated testing, and, of course, much, much more. What are you waiting for? There’s never been a better time – or a better way – to get into Android app development.
Table of Contents (16 chapters)
Learning Android Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

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 use the support library version...