NSC AD 340 5210 - Week 5

Df78ed2e647f52dadaac996721a6bdfb?s=47 Nate Ebel
May 10, 2020
43

NSC AD 340 5210 - Week 5

Df78ed2e647f52dadaac996721a6bdfb?s=128

Nate Ebel

May 10, 2020
Tweet

Transcript

  1. Week 5 Lecture Fragments

  2. What are we building this week? Building composable UI using

    Fragments 02 Project Demo Fragments 01
  3. Project Demo What are we building this week?

  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
  5. Fragments Building composable UI using Fragments

  6. How to reuse pieces of UI?

  7. Fragments Reusable portions of UI that can be composed together

    within a single Activity
  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
  9. Fragment 1 Fragment 2 Fragment 3 Composable UI Add &

    remove multiple fragments in a single screen
  10. Adding a Fragment Using XML <fragment 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
  11. Adding a Fragment Programmatically supportFragmentManager .beginTransaction() .add(R.id.root, Fragment()) .commit() MainActivity

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

  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
  14. Check Canvas For Additional Resources & Assignments