Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dive Into Android Fragments

Daf1617c9a4ff129239e922e8c56af1b?s=47 Donn Felker
November 14, 2013

Dive Into Android Fragments

Slides from the "Dive into Android Fragments" class at AnDevCon


Donn Felker

November 14, 2013


  1. #andevcon fragments dive into

  2. #andevcon DONN FELKER donn@donnfelker.com @donnfelker google.com/+DonnFelker

  3. #andevcon Groupon MyFitnessPal GetHuman Fitness+3 Travel WODs QONQR ... and

    over 50 more Android apps
  4. #andevcon https://github.com/donnfelker/fragments-demo

  5. #andevcon FRAGMENTS fragments image: wallbase.cc

  6. #andevcon REUSABLE CHUNKS OF CODE image from android developer blog

  7. #andevcon code.google.com/p/iosched/

  8. #andevcon fragment usage

  9. #andevcon List Fragment Vehicle Damage Waiver Fragment

  10. #andevcon TABLET VERSION - Single Screen

  11. #andevcon PHONE VERSION - Two Screens

  12. #andevcon Types of Fragments Fragment - Anything goes (for the

    most part) ListFragment - Lists. Yup. Thats it. Lists.
  13. #andevcon Fragment Lifecycle

  14. #andevcon You decide which layout the Fragment should return. ListFragment

    automatically returns a new list view for you! ... but, if you’re using a ListFragment
  15. #andevcon Fragments App Demo

  16. #andevcon Multipane Layouts with multiple Fragments fragment fragment fragment fragment

  17. #andevcon fragments can be instantiated via java or xml

  18. #andevcon XML

  19. #andevcon Code



  22. #andevcon List Fragment Vehicle Damage Waiver Fragment

  23. #andevcon How To Get Each Fragment to Talk to Each

  24. #andevcon Activity Fragment communication between

  25. #andevcon Communication Patterns Direct Activity Access Inversion of Control (interface)

    Event Bus
  26. #andevcon Inversion of Control via Interface /** * Contract between

    caller and receiver for red buttons */ public interface RedButtonListener { void onRedButtonClick(); } @Override public void onRedButtonClick() { Toast.makeText(this, R.string.red_button_clicked, Toast.LENGTH_SHORT).show(); } in Activity redButtonListener.onRedButtonClick(); in Fragment RedButtonListener.java
  27. #andevcon Otto An enhanced Guava-based event bus with emphasis on

    Android support.
  28. #andevcon goal - decouple and eliminate code Otto is Pub/Sub

  29. #andevcon Otto as an event bus . The activity is

    no longer the orchestrator. Activity ListFragment Waiver VehicleSelected manually Previous - Use Interface Now - No Interface Activity ListFragment Waiver Fragment fragments know of activity activity is simply a container Otto Otto moves messages to and from subscribers (observer pattern / event bus)
  30. #andevcon Fragment Communication Demo

  31. #andevcon Action Tabs

  32. #andevcon Action Tabs Demo

  33. #andevcon Responsive Layout

  34. #andevcon Detect Size on App Init How?

  35. #andevcon NavigationFragment in DrawerLayout Content fragment in the content area

  36. #andevcon Navigation Fragment is fixed on the left content fragment

    on the right Tablet
  37. #andevcon Simple Responsive Layout Demo

  38. #andevcon Advanced Fragment Usage

  39. #andevcon Wizards Guiding users through complex flows easily. Example: Registration

  40. #andevcon Wizard Demo Step 2

  41. #andevcon Wizard Demo

  42. #andevcon ViewPager ViewPageIndicator viewpageindicator.com

  43. #andevcon Fragments Managing other Fragments

  44. #andevcon Activity Fragment A Fragment B Fragments Inside of Fragments

    Fragment Y Fragment X
  45. #andevcon

  46. #andevcon View Pager & ChildFragmentManager Demo

  47. #andevcon DONN FELKER donn@donnfelker.com @donnfelker google.com/+DonnFelker THANK YOU. CODE: github.com/donnfelker/fragments-demo