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

NSC AD 340 5210 - Week 5

Nate Ebel
May 10, 2020
310

NSC AD 340 5210 - Week 5

Nate Ebel

May 10, 2020
Tweet

Transcript

  1. Week 5
    Lecture
    Fragments

    View full-size slide

  2. What are we building
    this week?
    Building composable UI using
    Fragments
    02
    Project Demo Fragments
    01

    View full-size slide

  3. Project Demo
    What are we building
    this week?

    View full-size slide

  4. Week 5 Project
    Updates
    ● Create a LocationEntryFragment
    ● Create a CurrentForecastFragment
    ● Create an AppNavigator interface to navigate between fragments
    ● Add a FloatingActionButton to show LocationEntryFragment after
    forecast data is displayed

    View full-size slide

  5. Fragments
    Building composable UI
    using Fragments

    View full-size slide

  6. How to reuse pieces
    of UI?

    View full-size slide

  7. Fragments
    Reusable portions of UI that can be
    composed together within a single Activity

    View full-size slide

  8. Fragment
    Has its own layout and
    lifecycle. Can be defined in
    XML or added/removed
    programmatically
    FragmentManager
    Manages what Fragments
    are currently showing on
    the screen. Use the
    FragmentManager to
    add/remove a Fragment.
    FragmentTransaction
    Represents the addition or
    removal of a single
    Fragment from its
    container.
    Fragments

    View full-size slide

  9. Fragment 1
    Fragment 2 Fragment 3
    Composable UI
    Add & remove multiple
    fragments in a single screen

    View full-size slide

  10. Adding a Fragment Using XML
    android:id="@+id/locationEntryFragment"
    android:name="com.goobar.io.ad340.location.LocationEntryFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
    activity_main.xml

    View full-size slide

  11. Adding a Fragment Programmatically
    supportFragmentManager
    .beginTransaction()
    .add(R.id.root, Fragment())
    .commit()
    MainActivity

    View full-size slide

  12. Fragment Lifecycle
    Fragment lifecycle is very similar to Activity
    lifecycle

    View full-size slide

  13. Fragment Lifecycle
    onAttach()
    Added to Activity
    onStart()
    Fragment is visible on screen
    onStop()
    Fragment no longer visible
    onCreateView()
    Fragment layout is inflated
    and returned
    onPause()
    Fragment has been removed
    onDestroyView()
    Fragment view is destroyed
    onResume()
    Fragment is active on screen
    onDetach()
    Fragment is removed from
    Activity

    View full-size slide

  14. Check Canvas For
    Additional Resources
    & Assignments

    View full-size slide