You are previewing Creating Dynamic UI with Android Fragments.
O'Reilly logo
Creating Dynamic UI with Android Fragments

Book Description

Make your Android apps a superior, silky-smooth experience for the end-user with this comprehensive guide to creating a dynamic and multi-pane UI. Everything you need to know in one handy volume.

  • Learn everything you need to know to provide dynamic multi-screen UIs within a single activity

  • Integrate the rich UI features demanded by today’s mobile users

  • Understand the basics of using fragments and how to use them to create more adaptive and dynamic user experiences

  • In Detail

    To create a dynamic and multi-pane user interface on Android, you need to encapsulate UI components and activity behaviors into modules that you can swap into and out of your activities. You can create these modules with the fragment class, which behaves somewhat like a nested activity that can define its own layout and manage its own lifecycle. When a fragment specifies its own layout, it can be configured in different combinations with other fragments inside an activity to modify your layout configuration for different screen sizes (a small screen might show one fragment at a time, but a large screen can show two or more).

    Creating Dynamic UI with Android Fragments shows you how to create modern Android applications that meet the high expectations of today’s users. You will learn how to incorporate rich navigation features like swipe-based screen browsing and how to create adaptive UIs that ensure your application looks fantastic whether run on a low cost smartphone or the latest tablet.

    This book looks at the impact fragments have on Android UI design and their role in both simplifying many common UI challenges and providing new ways to incorporate rich UI behaviors.

    You will learn how to use fragments to create UIs that automatically adapt to device differences. We look closely at the roll of fragment transactions and how to work with the Android back stack. Leveraging this understanding, we then explore several specialized fragment-related classes like ListFragment and DialogFragment as well as rich navigation features like swipe-based screen browsing.

    Table of Contents

    1. Creating Dynamic UI with Android Fragments
      1. Table of Contents
      2. Creating Dynamic UI with Android Fragments
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Fragments and UI Modularization
        1. The need for a new approach to UI creation
          1. The broad platform support of fragments
          2. Fragments simplify common Android tasks
          3. The relationship between fragments and activities
        2. Making the shift to fragments
          1. The old thinking – activity-oriented
            1. Defining the activity appearance
            2. Displaying the activity UI
          2. The new thinking – fragment-oriented
            1. Creating the fragment layout resources
              1. Defining the layout as a reusable list
              2. Minimize assumptions
              3. Encapsulating the display layout
            2. Creating the Fragment class
              1. Wrapping the list in a fragment
              2. Providing the display fragment
            3. Converting the activity to use fragments
              1. Activities and backward compatibility
        3. Summary
      10. 2. Fragments and UI Flexibility
        1. Creating UI flexibility
          1. Dynamic fragment layout selection
            1. Adding an alternate layout resource
            2. Managing fragment layout by screen size
              1. Resource screen size groups
              2. Resource screen size qualifiers
            3. Eliminating redundancy
              1. Layout aliasing
          2. Design fragments for flexibility
            1. Avoiding tight coupling
            2. Abstracting fragment relationships
              1. Defining the callback interface
              2. Making the fragment self-contained
              3. Fragment notification
            3. Encapsulating fragment operations
            4. Loosely connecting the pieces
        2. Fragments protect against the unexpected
          1. Evolving layout resource files
          2. Creating the book description activity
          3. Making the MainActivity class adaptive
        3. Summary
      11. 3. Fragment Lifecycle and Specialization
        1. Understanding the fragment lifecycle
          1. Understanding fragment setup and display
            1. Avoiding method name confusion
          2. Understanding fragment hide and teardown
          3. Maximizing available resources
            1. Managing a fragment state
        2. Special purpose fragment classes
          1. ListFragment
            1. Associating data with the list
            2. Separating data from display
              1. Creating the ListFragment derived class
              2. Handling ListFragment item selection
              3. Updating the layout resources
          2. DialogFragment
            1. Styles
            2. Layout
            3. DialogFragment display
            4. Event handling
            5. Dialog identity
              1. Accessing Dialog related behavior
              2. Wrapping an existing dialog in a fragment
        3. Summary
      12. 4. Working with Fragment Transactions
        1. Intentional screen management
        2. Dynamically managing fragments
          1. Deferred execution of transaction changes
          2. Adding and removing fragments
          3. Supporting the back button
        3. Creating an adaptive application layout
          1. Updating the layout to support dynamic fragments
          2. Adapting to device differences
          3. Dynamically loading a fragment at startup
          4. Transitioning between fragments
            1. Eliminating redundant handling
            2. Creating the fragment on-the-fly
            3. Managing asynchronous creation
            4. Putting it all together
        4. Summary
      13. 5. Creating Rich Navigation with Fragments
        1. A brave new world
        2. Making navigation fun with swipe
          1. Implementing swipe navigation
            1. Managing the swipe fragments
            2. Putting the swipe UI into place
            3. Android Studio and swipe navigation
        3. Improving navigation with the ActionBar
          1. Navigating randomly with tabs
            1. Managing tab selection
            2. Connecting the fragments to the tabs
          2. Providing direct access with drop-down list navigation
            1. Managing fragment selection
            2. Providing the navigation choices
            3. Android Studio and drop-down list navigation
        4. Summary
      14. Index