Download - Fragments What are they good for?
![Page 1: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/1.jpg)
Fragments:WHAT ARE THEY GOOD FOR?
![Page 2: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/2.jpg)
![Page 3: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/3.jpg)
![Page 4: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/4.jpg)
Overview
uWhy Fragments? uDifferent typesuAnatomyu LifecycleuHow to useuCommon UsageuBest Practices
![Page 5: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/5.jpg)
![Page 6: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/6.jpg)
![Page 7: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/7.jpg)
Types of Fragments
![Page 8: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/8.jpg)
![Page 9: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/9.jpg)
![Page 10: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/10.jpg)
Static Fragment Example
![Page 11: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/11.jpg)
Dynamic Fragments
![Page 12: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/12.jpg)
Dynamic Fragment uRequire ContaineruFrameworkuSupport
![Page 13: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/13.jpg)
Framework Fragments
![Page 14: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/14.jpg)
Support Fragments
![Page 15: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/15.jpg)
![Page 16: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/16.jpg)
Fragment Lifecycle
![Page 17: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/17.jpg)
![Page 18: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/18.jpg)
![Page 19: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/19.jpg)
![Page 20: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/20.jpg)
![Page 21: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/21.jpg)
onAttach ( )
![Page 22: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/22.jpg)
onAttach( ) Example
![Page 23: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/23.jpg)
onCreateView ( )
![Page 24: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/24.jpg)
onCreateView( ) Example
![Page 25: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/25.jpg)
onCreateView( ) Fixes
uView – Hold Parametersu Inflater – Add LayoutuView Container – Collection for ViewsuBundle –Reconstructs Fragment
![Page 26: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/26.jpg)
onActivityCreated( )
![Page 27: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/27.jpg)
onActivityCreated( ) Example
![Page 28: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/28.jpg)
Standard Lifecycle ( )’s
uonStart( )uonResume( )uonPause( )
![Page 29: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/29.jpg)
onDestroyView ( )
![Page 30: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/30.jpg)
onDestroyView( ) Example
![Page 31: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/31.jpg)
onDetach ( )
![Page 32: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/32.jpg)
onDetach( ) Example
![Page 33: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/33.jpg)
newInstance( )
uSet up FragmentuDefault DatauBundleuSetArgs( )uGetArgs( )
![Page 34: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/34.jpg)
New Instance( ) Example
![Page 35: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/35.jpg)
How to Use
![Page 36: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/36.jpg)
![Page 37: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/37.jpg)
Fragment Manager
uManages Fragments in ActivityuHolds list of FragmentsuPerform TransactionsuFluent Interface
![Page 38: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/38.jpg)
Fragment Manager Example
![Page 39: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/39.jpg)
Fragment ID
![Page 40: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/40.jpg)
Fragment TAG
![Page 41: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/41.jpg)
Identifying a Fragment
u findFragmentById ( ) – Container IDu findFragmentByTag( ) – String Constant
![Page 42: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/42.jpg)
Fragment Transaction
![Page 43: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/43.jpg)
Parts of a Transaction
beginTransaction( )
Action
commit( )
![Page 44: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/44.jpg)
Basic Add, ID Example
![Page 45: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/45.jpg)
Common Usageu Tabletu Tab LayoutuDialog Fragment
![Page 46: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/46.jpg)
Tablet
![Page 47: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/47.jpg)
Master Detail Flow
![Page 48: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/48.jpg)
Fragments in Tablet
uDual Pane condition – Use Boolean uResource Qualifier
![Page 49: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/49.jpg)
Resource Qualifier
![Page 50: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/50.jpg)
Resource QualifieruChange ConfigurationuScreen Width u600 DPI – Tablet
![Page 51: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/51.jpg)
Resource Qualifier Example
![Page 52: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/52.jpg)
Tablet Example
![Page 53: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/53.jpg)
Tab Layout
![Page 54: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/54.jpg)
Tab Layout
uDesign Support LibraryuFixed Tabs – Most Common
![Page 55: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/55.jpg)
View Pager
![Page 56: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/56.jpg)
View Pager
uFlip through pagesuSupport v4
![Page 57: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/57.jpg)
Pager Adapter: 2 types
![Page 58: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/58.jpg)
Fragment Pager Adapter
![Page 59: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/59.jpg)
Fragment State Pager Adapter
![Page 60: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/60.jpg)
Pager Adapter
ugetCount( ) – Number of FragmentsugetItem( ) – Position of FragmentsuFragment Pager Adapter uFragment State Pager Adapter
![Page 61: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/61.jpg)
Tab Layout & View Pager
![Page 62: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/62.jpg)
Dialog Fragment
![Page 63: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/63.jpg)
Dialog Fragment
![Page 64: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/64.jpg)
Dialog FragmentuRestores AlertDialoguonCreateView( )uonCreateDialog( )
![Page 65: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/65.jpg)
onCreateDialog( ) Example
![Page 66: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/66.jpg)
Dialog Fragment Ex.
![Page 67: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/67.jpg)
Odds and Ends
uNavigation DraweruChild FragmentsuHeadless Fragments
![Page 68: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/68.jpg)
![Page 69: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/69.jpg)
![Page 70: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/70.jpg)
Child Fragments
![Page 71: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/71.jpg)
Headless Fragments
![Page 72: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/72.jpg)
Best Practices
u3 – Fragments Activitiesu5 – Fragments Tab LayoutsuUse Interfaces with ActivitiesuCreate early
![Page 73: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/73.jpg)
![Page 74: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/74.jpg)
![Page 75: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/75.jpg)
![Page 76: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/76.jpg)
Thank you
@HopeDeveloper
![Page 77: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/77.jpg)
![Page 78: Fragments What are they good for?](https://reader031.vdocument.in/reader031/viewer/2022022412/58f2cdfc1a28ab09248b45a3/html5/thumbnails/78.jpg)
Questions?