Review how to statically add a fragment
https://github.com/dltra/FragmentExampleStatic/commits
Note: The onClick() method referenced by the Button in the fragment_a.xml is located in the its parent activity (MainActivity.java instead of FragmentA.java).
Make an application to demonstrate the following with fragments added dynamically
FragmentTransaction
add(), replace(), remove(), hide(), show()
Assign a "TAG" to a fragment and access that fragment by findFragmentByTag()
Use a Bundle to pass arguments to a Fragment
Optional: use getChildFragmentManager() to use Fragment nesting
https://www.c-sharpcorner.com/UploadFile/1e5156/dynamically-add-fragment-in-android-studio/
https://www.dev2qa.com/android-add-fragment-to-activity-dynamically-example/
Additional notes from student experience:
view.getParent() - returns view's container
With an instance within a fragment (button for example):
view.getParent().getParent() would return the container of the fragment - often times a FrameLayout
In the following replacement code, please note that once ft has been committed, that transaction is done. You can't add anymore changes. You'd need to begin a new transaction and may assign it to ft if you want to initiate new fragment modifications.
// Begin the transaction
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.your_placeholder, new FooFragment());
ft.commit();
Fragment Lifecycle
Advantages
Build the .apk file
Rename the .apk file
PeriodLabNumberLastFirstCustomName.apk
P8L07aTraDanFragments.apk
Submit assignment
Fragment class files
MainActivity.java
associated .xml files
Video of fragment changes
.apk file
Add fragments encapsulating a text message (name, time, message, color, etc)
Flip through profile of people, special characters, animals, ...etc.
Turn each of your previous labs into fragments.
Submit as Lab07b
P8L07bTraDanFragments.apk
Submit video as appropriate