fragments what are they good for?

78
Fragments: WHAT ARE THEY GOOD FOR?

Upload: hopedeveloper

Post on 16-Apr-2017

43 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Fragments What are they good for?

Fragments:WHAT ARE THEY GOOD FOR?

Page 2: Fragments What are they good for?
Page 3: Fragments What are they good for?
Page 4: Fragments What are they good for?

Overview

uWhy Fragments? uDifferent typesuAnatomyu LifecycleuHow to useuCommon UsageuBest Practices

Page 5: Fragments What are they good for?
Page 6: Fragments What are they good for?
Page 7: Fragments What are they good for?

Types of Fragments

Page 8: Fragments What are they good for?
Page 9: Fragments What are they good for?
Page 10: Fragments What are they good for?

Static Fragment Example

Page 11: Fragments What are they good for?

Dynamic Fragments

Page 12: Fragments What are they good for?

Dynamic Fragment uRequire ContaineruFrameworkuSupport

Page 13: Fragments What are they good for?

Framework Fragments

Page 14: Fragments What are they good for?

Support Fragments

Page 15: Fragments What are they good for?
Page 16: Fragments What are they good for?

Fragment Lifecycle

Page 17: Fragments What are they good for?
Page 18: Fragments What are they good for?
Page 19: Fragments What are they good for?
Page 20: Fragments What are they good for?
Page 21: Fragments What are they good for?

onAttach ( )

Page 22: Fragments What are they good for?

onAttach( ) Example

Page 23: Fragments What are they good for?

onCreateView ( )

Page 24: Fragments What are they good for?

onCreateView( ) Example

Page 25: Fragments What are they good for?

onCreateView( ) Fixes

uView – Hold Parametersu Inflater – Add LayoutuView Container – Collection for ViewsuBundle –Reconstructs Fragment

Page 26: Fragments What are they good for?

onActivityCreated( )

Page 27: Fragments What are they good for?

onActivityCreated( ) Example

Page 28: Fragments What are they good for?

Standard Lifecycle ( )’s

uonStart( )uonResume( )uonPause( )

Page 29: Fragments What are they good for?

onDestroyView ( )

Page 30: Fragments What are they good for?

onDestroyView( ) Example

Page 31: Fragments What are they good for?

onDetach ( )

Page 32: Fragments What are they good for?

onDetach( ) Example

Page 33: Fragments What are they good for?

newInstance( )

uSet up FragmentuDefault DatauBundleuSetArgs( )uGetArgs( )

Page 34: Fragments What are they good for?

New Instance( ) Example

Page 35: Fragments What are they good for?

How to Use

Page 36: Fragments What are they good for?
Page 37: Fragments What are they good for?

Fragment Manager

uManages Fragments in ActivityuHolds list of FragmentsuPerform TransactionsuFluent Interface

Page 38: Fragments What are they good for?

Fragment Manager Example

Page 39: Fragments What are they good for?

Fragment ID

Page 40: Fragments What are they good for?

Fragment TAG

Page 41: Fragments What are they good for?

Identifying a Fragment

u findFragmentById ( ) – Container IDu findFragmentByTag( ) – String Constant

Page 42: Fragments What are they good for?

Fragment Transaction

Page 43: Fragments What are they good for?

Parts of a Transaction

beginTransaction( )

Action

commit( )

Page 44: Fragments What are they good for?

Basic Add, ID Example

Page 45: Fragments What are they good for?

Common Usageu Tabletu Tab LayoutuDialog Fragment

Page 46: Fragments What are they good for?

Tablet

Page 47: Fragments What are they good for?

Master Detail Flow

Page 48: Fragments What are they good for?

Fragments in Tablet

uDual Pane condition – Use Boolean uResource Qualifier

Page 49: Fragments What are they good for?

Resource Qualifier

Page 50: Fragments What are they good for?

Resource QualifieruChange ConfigurationuScreen Width u600 DPI – Tablet

Page 51: Fragments What are they good for?

Resource Qualifier Example

Page 52: Fragments What are they good for?

Tablet Example

Page 53: Fragments What are they good for?

Tab Layout

Page 54: Fragments What are they good for?

Tab Layout

uDesign Support LibraryuFixed Tabs – Most Common

Page 55: Fragments What are they good for?

View Pager

Page 56: Fragments What are they good for?

View Pager

uFlip through pagesuSupport v4

Page 57: Fragments What are they good for?

Pager Adapter: 2 types

Page 58: Fragments What are they good for?

Fragment Pager Adapter

Page 59: Fragments What are they good for?

Fragment State Pager Adapter

Page 60: Fragments What are they good for?

Pager Adapter

ugetCount( ) – Number of FragmentsugetItem( ) – Position of FragmentsuFragment Pager Adapter uFragment State Pager Adapter

Page 61: Fragments What are they good for?

Tab Layout & View Pager

Page 62: Fragments What are they good for?

Dialog Fragment

Page 63: Fragments What are they good for?

Dialog Fragment

Page 64: Fragments What are they good for?

Dialog FragmentuRestores AlertDialoguonCreateView( )uonCreateDialog( )

Page 65: Fragments What are they good for?

onCreateDialog( ) Example

Page 66: Fragments What are they good for?

Dialog Fragment Ex.

Page 67: Fragments What are they good for?

Odds and Ends

uNavigation DraweruChild FragmentsuHeadless Fragments

Page 68: Fragments What are they good for?
Page 69: Fragments What are they good for?
Page 70: Fragments What are they good for?

Child Fragments

Page 71: Fragments What are they good for?

Headless Fragments

Page 72: Fragments What are they good for?

Best Practices

u3 – Fragments Activitiesu5 – Fragments Tab LayoutsuUse Interfaces with ActivitiesuCreate early

Page 73: Fragments What are they good for?
Page 74: Fragments What are they good for?
Page 75: Fragments What are they good for?
Page 76: Fragments What are they good for?

Thank you

@HopeDeveloper

Page 77: Fragments What are they good for?
Page 78: Fragments What are they good for?

Questions?