fragments what are they good for?

Post on 16-Apr-2017

43 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Fragments:WHAT ARE THEY GOOD FOR?

Overview

uWhy Fragments? uDifferent typesuAnatomyu LifecycleuHow to useuCommon UsageuBest Practices

Types of Fragments

Static Fragment Example

Dynamic Fragments

Dynamic Fragment uRequire ContaineruFrameworkuSupport

Framework Fragments

Support Fragments

Fragment Lifecycle

onAttach ( )

onAttach( ) Example

onCreateView ( )

onCreateView( ) Example

onCreateView( ) Fixes

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

onActivityCreated( )

onActivityCreated( ) Example

Standard Lifecycle ( )’s

uonStart( )uonResume( )uonPause( )

onDestroyView ( )

onDestroyView( ) Example

onDetach ( )

onDetach( ) Example

newInstance( )

uSet up FragmentuDefault DatauBundleuSetArgs( )uGetArgs( )

New Instance( ) Example

How to Use

Fragment Manager

uManages Fragments in ActivityuHolds list of FragmentsuPerform TransactionsuFluent Interface

Fragment Manager Example

Fragment ID

Fragment TAG

Identifying a Fragment

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

Fragment Transaction

Parts of a Transaction

beginTransaction( )

Action

commit( )

Basic Add, ID Example

Common Usageu Tabletu Tab LayoutuDialog Fragment

Tablet

Master Detail Flow

Fragments in Tablet

uDual Pane condition – Use Boolean uResource Qualifier

Resource Qualifier

Resource QualifieruChange ConfigurationuScreen Width u600 DPI – Tablet

Resource Qualifier Example

Tablet Example

Tab Layout

Tab Layout

uDesign Support LibraryuFixed Tabs – Most Common

View Pager

View Pager

uFlip through pagesuSupport v4

Pager Adapter: 2 types

Fragment Pager Adapter

Fragment State Pager Adapter

Pager Adapter

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

Tab Layout & View Pager

Dialog Fragment

Dialog Fragment

Dialog FragmentuRestores AlertDialoguonCreateView( )uonCreateDialog( )

onCreateDialog( ) Example

Dialog Fragment Ex.

Odds and Ends

uNavigation DraweruChild FragmentsuHeadless Fragments

Child Fragments

Headless Fragments

Best Practices

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

Thank you

@HopeDeveloper

Questions?

top related