SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
But in tablet...
Do I really need to write everything twice?
NO!
Fragments
●   “Part of the screen”
●   Introduced in Android 3.0 (API 11).
●   Available for older Android platforms via
    support package / library.
●   Allows us to change activity appearance at
    runtime without complex changes.
Fragments philosophy
Creating a fragment
●   Extend Fragment class.
●   Implement fragment Callbacks.
Fragment life cycle
Fragment Callbacks
●   OnCreate()
    –   Called when first creating the fragment.
    –   Initialize members here.
●   OnCreateView()
    –   Called when the fragments needs to be displayed
        on screen.
    –   Must return a view object.
Fragment Callbacks
●   OnPause()
    –   Called when the user leaves the fragment
●   OnDestroy
    –   Called when fragment is destroyed.
OnCreateView example
Adding fragment to activity / layout
Adding fragment to activity
●   Activity should extends fragmentActivity
    instead of Activity
Communicating with the activity
●   Fragment side:
    –   GetActivity() - returns a reference to the containing
        activity.


●   Activity Side:
Communicating with activity
●   Often a fragment needs to share events with
    its activity.
    –   For example: itemClicked.


●   Fragment should define a callback interface
Communicating with activity - cont
●   Activity should implement that callback
    interface.
●   Fragment holds reference to that listener and
    notifies it when needed.
Checkpoint 0
●   Checkout checkpoint0 branch from
    https://github.com/RanNachmany/AndconLab
●   Adjust project to use actionBarSherlock
●   Run.
Checkpoint 1
●   Create a fragment that displays a list of all
    lectures.
●   Change MainActivity to use the new fragment.
●   Do the same for SingleLectureActivity.
●   Don't forget to implement callback interface.
Supporting tablets
●   How activity A will change its layout from one
    fragment to two dynamically?
●   The answer: xml qualifiers.
    –   We will create two xml layouts. One for phone, and
        one for tablet.
    –   OS will choose the right layout during runtime.
    –   Good qualifier: sw-600. Smallest width: 600.
        ●   Located at res/layout-sw600dp
Changing fragments programatically
Checkpoint 2
●   Add main_activity layout under sw-600
    qualifier.
●   Adjust MainActivity code.
●   Test on phone and tablet.
●   Bring world peace.

Mais conteúdo relacionado

Mais procurados

Express lane video 4 autoresp
Express lane video 4   autorespExpress lane video 4   autoresp
Express lane video 4 autorespChuck Milliken
 
Automating with FME 2019
Automating with FME 2019Automating with FME 2019
Automating with FME 2019Safe Software
 
Domains in apikit
Domains in apikitDomains in apikit
Domains in apikitfedefortin
 
Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?Anthony Brown
 
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinC# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinXamarin
 
Cloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground upCloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground upAna-Maria Mihalceanu
 
Benefits of Serverless
Benefits of ServerlessBenefits of Serverless
Benefits of ServerlessAWS UG PK
 
The Ember.js Run Loop
The Ember.js Run LoopThe Ember.js Run Loop
The Ember.js Run LoopRizwan Reza
 
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of XamarinC# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of XamarinXamarin
 
Deploying Rails Apps with Capistrano
Deploying Rails Apps with CapistranoDeploying Rails Apps with Capistrano
Deploying Rails Apps with CapistranoNyros Technologies
 
The Anatomy of a Seriously Sophisticated AIR Application
The Anatomy of a Seriously Sophisticated AIR ApplicationThe Anatomy of a Seriously Sophisticated AIR Application
The Anatomy of a Seriously Sophisticated AIR ApplicationAdam Creeger
 
Intro to Netflix's Chaos Monkey
Intro to Netflix's Chaos MonkeyIntro to Netflix's Chaos Monkey
Intro to Netflix's Chaos MonkeyMichael Whitehead
 
Real Time with Rails 5
Real Time with Rails 5Real Time with Rails 5
Real Time with Rails 5Lucas Renan
 
Gigigo Rails Workshop
Gigigo Rails WorkshopGigigo Rails Workshop
Gigigo Rails WorkshopAlex Rupérez
 
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...Codemotion
 
Synchronization in Selenium WebDriver
Synchronization in Selenium WebDriverSynchronization in Selenium WebDriver
Synchronization in Selenium WebDriverSHUBHAM PATIL
 

Mais procurados (19)

Express lane video 4 autoresp
Express lane video 4   autorespExpress lane video 4   autoresp
Express lane video 4 autoresp
 
Automating with FME 2019
Automating with FME 2019Automating with FME 2019
Automating with FME 2019
 
Extreme automation
Extreme automationExtreme automation
Extreme automation
 
Domains in apikit
Domains in apikitDomains in apikit
Domains in apikit
 
Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?
 
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinC# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
 
NATE-CHEF
NATE-CHEFNATE-CHEF
NATE-CHEF
 
Cloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground upCloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground up
 
Benefits of Serverless
Benefits of ServerlessBenefits of Serverless
Benefits of Serverless
 
The Ember.js Run Loop
The Ember.js Run LoopThe Ember.js Run Loop
The Ember.js Run Loop
 
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of XamarinC# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
 
Deploying Rails Apps with Capistrano
Deploying Rails Apps with CapistranoDeploying Rails Apps with Capistrano
Deploying Rails Apps with Capistrano
 
The Anatomy of a Seriously Sophisticated AIR Application
The Anatomy of a Seriously Sophisticated AIR ApplicationThe Anatomy of a Seriously Sophisticated AIR Application
The Anatomy of a Seriously Sophisticated AIR Application
 
Event Source On Labs
Event Source On LabsEvent Source On Labs
Event Source On Labs
 
Intro to Netflix's Chaos Monkey
Intro to Netflix's Chaos MonkeyIntro to Netflix's Chaos Monkey
Intro to Netflix's Chaos Monkey
 
Real Time with Rails 5
Real Time with Rails 5Real Time with Rails 5
Real Time with Rails 5
 
Gigigo Rails Workshop
Gigigo Rails WorkshopGigigo Rails Workshop
Gigigo Rails Workshop
 
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
 
Synchronization in Selenium WebDriver
Synchronization in Selenium WebDriverSynchronization in Selenium WebDriver
Synchronization in Selenium WebDriver
 

Semelhante a Multi screenlab

Lecture #4 activities & fragments
Lecture #4  activities & fragmentsLecture #4  activities & fragments
Lecture #4 activities & fragmentsVitali Pekelis
 
Android design patterns
Android design patternsAndroid design patterns
Android design patternsPlatty Soft
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React NativeEric Deng
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptJohn Stevenson
 
Kubernetes and CoreOS @ Athens Docker meetup
Kubernetes and CoreOS @ Athens Docker meetupKubernetes and CoreOS @ Athens Docker meetup
Kubernetes and CoreOS @ Athens Docker meetupMist.io
 
Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3
Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3
Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3Paris Android User Group
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...Codemotion
 
Javascript training sample
Javascript training sampleJavascript training sample
Javascript training sampleprahalad_das_in
 
Let's Talk Locks!
Let's Talk Locks!Let's Talk Locks!
Let's Talk Locks!C4Media
 
Introducing Honeycomb
Introducing HoneycombIntroducing Honeycomb
Introducing HoneycombCommonsWare
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
Getting started with react basics
Getting started with react basicsGetting started with react basics
Getting started with react basicsKnoldus Inc.
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshopAssaf Gannon
 
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012Tomáš Kypta
 
Android Lollipop: The developer's perspective
Android Lollipop: The developer's perspectiveAndroid Lollipop: The developer's perspective
Android Lollipop: The developer's perspectiveSebastian Vieira
 

Semelhante a Multi screenlab (20)

Lecture #4 activities & fragments
Lecture #4  activities & fragmentsLecture #4  activities & fragments
Lecture #4 activities & fragments
 
Android design patterns
Android design patternsAndroid design patterns
Android design patterns
 
React native
React nativeReact native
React native
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
 
Fragment
Fragment Fragment
Fragment
 
Kubernetes and CoreOS @ Athens Docker meetup
Kubernetes and CoreOS @ Athens Docker meetupKubernetes and CoreOS @ Athens Docker meetup
Kubernetes and CoreOS @ Athens Docker meetup
 
fragments-activity.pptx
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
 
Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3
Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3
Introduction to Honeycomb APIs - Android Developer Lab 2011 Q3
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Javascript training sample
Javascript training sampleJavascript training sample
Javascript training sample
 
Runtime surgery
Runtime surgeryRuntime surgery
Runtime surgery
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Let's Talk Locks!
Let's Talk Locks!Let's Talk Locks!
Let's Talk Locks!
 
Introducing Honeycomb
Introducing HoneycombIntroducing Honeycomb
Introducing Honeycomb
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Getting started with react basics
Getting started with react basicsGetting started with react basics
Getting started with react basics
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshop
 
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012
 
Android Lollipop: The developer's perspective
Android Lollipop: The developer's perspectiveAndroid Lollipop: The developer's perspective
Android Lollipop: The developer's perspective
 

Multi screenlab

  • 1.
  • 2.
  • 4. Do I really need to write everything twice?
  • 5. NO!
  • 6. Fragments ● “Part of the screen” ● Introduced in Android 3.0 (API 11). ● Available for older Android platforms via support package / library. ● Allows us to change activity appearance at runtime without complex changes.
  • 8. Creating a fragment ● Extend Fragment class. ● Implement fragment Callbacks.
  • 10. Fragment Callbacks ● OnCreate() – Called when first creating the fragment. – Initialize members here. ● OnCreateView() – Called when the fragments needs to be displayed on screen. – Must return a view object.
  • 11. Fragment Callbacks ● OnPause() – Called when the user leaves the fragment ● OnDestroy – Called when fragment is destroyed.
  • 13. Adding fragment to activity / layout
  • 14. Adding fragment to activity ● Activity should extends fragmentActivity instead of Activity
  • 15. Communicating with the activity ● Fragment side: – GetActivity() - returns a reference to the containing activity. ● Activity Side:
  • 16. Communicating with activity ● Often a fragment needs to share events with its activity. – For example: itemClicked. ● Fragment should define a callback interface
  • 17. Communicating with activity - cont ● Activity should implement that callback interface. ● Fragment holds reference to that listener and notifies it when needed.
  • 18. Checkpoint 0 ● Checkout checkpoint0 branch from https://github.com/RanNachmany/AndconLab ● Adjust project to use actionBarSherlock ● Run.
  • 19. Checkpoint 1 ● Create a fragment that displays a list of all lectures. ● Change MainActivity to use the new fragment. ● Do the same for SingleLectureActivity. ● Don't forget to implement callback interface.
  • 20. Supporting tablets ● How activity A will change its layout from one fragment to two dynamically? ● The answer: xml qualifiers. – We will create two xml layouts. One for phone, and one for tablet. – OS will choose the right layout during runtime. – Good qualifier: sw-600. Smallest width: 600. ● Located at res/layout-sw600dp
  • 21.
  • 23. Checkpoint 2 ● Add main_activity layout under sw-600 qualifier. ● Adjust MainActivity code. ● Test on phone and tablet. ● Bring world peace.