Introduction to fragments in android


Published on

Introduction to fragments in android by Ritesh Bhattarai

Published in: Technology
  • Be the first to comment

Introduction to fragments in android

  1. 1. An Introduction ToFragments In Android By: Ritesh Bhattarai ( 13th October, 2012
  2. 2. What is a fragment?A fragment is, as the name suggests, a chunkof user interface with its own lifecycle whichmust exist within an activity.Multiple fragments can be used in a singleactivity to form a multi-pane UI or reuse afragment in multiple activities.
  3. 3. Advantages of fragments• It can modularize a single activity into smaller units of UI, making it more flexible and easier to manage.• A fragment can exist without a UI screen and act as an invisible worker for the activity.• A fragment can be reused with multiple activities.• A fragment lets us maintain a "back-stack" of its state.
  4. 4. Implementation in different screens
  5. 5. Implementations in paged layouts
  6. 6. Writing Fragment LayoutA fragment layout is similar to an activity layout.
  7. 7. Writing A Basic Fragment Class
  8. 8. Including Fragment Into Main Layout
  9. 9. Writing Main Activity Class
  10. 10. Fragment TypesListFragmentDialogFragmentCustom Fragment (e.g Grid)
  11. 11. CompatibilityYou can download the compatibility package using the AndroidSDK Manager as shown below.
  12. 12. Compatibility (contd.)To use the compatibility package, you must addit to your project and include in the build path.This can be done by Right clicking your Androidproject-> Selecting Android Tools-> Addcompatibility Library.
  13. 13. ResourcesAPI Guide
  14. 14. Thank You