SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
Android Fragment
2012/11/19 John
Fragment
A Fragment represents a behavior or a portion of user interface in an Activity.
You can combine multiple fragments in a single activity to build a multi-pane UI
and reuse a fragment in multiple activities. You can think of a fragment as a
modular section of an activity, which has its own lifecycle, receives its own input
events, and which you can add or remove while the activity is running (sort of
like a "sub activity" that you can reuse in different activities).
A fragment must always be embedded in an activity and the fragment's lifecycle
is directly affected by the host activity's lifecycle. For example, when the activity
is paused, so are all fragments in it, and when the activity is destroyed, so are
all fragments. However, while an activity is running (it is in the resumed lifecycle
state), you can manipulate each fragment independently, such as add or
remove them. When you perform such a fragment transaction, you can also
add it to a back stack that's managed by the activity—each back stack entry in
the activity is a record of the fragment transaction that occurred. The back stack
allows the user to reverse a fragment transaction (navigate backwards), by
pressing the Back button.
Design Philosophy
For example—to continue with the news application example—the application
can embed two fragments in Activity A, when running on a tablet-sized device.
However, on a handset-sized screen, there's not enough room for both
fragments, so Activity A includes only the fragment for the list of articles, and
when the user selects an article, it starts Activity B, which includes the second
fragment to read the article. Thus, the application supports both tablets and
handsets by reusing fragments in different combinations, as illustrated in figure
1.
Creating a Fragment
To create a fragment, you must create a
subclass of Fragment (or an existing subclass of
it). The Fragment class has code that looks a lot
like an Activity. It contains callback methods
similar to an activity, such as onCreate(),
onStart(), onPause(), and onStop(). In fact, if
you're converting an existing Android application
to use fragments, you might simply move code
from your activity's callback methods into the
respective callback methods of your fragment.
Handling the Fragment Lifecycle
Also like an activity, you can retain the state of
a fragment using a Bundle, in case the
activity's process is killed and you need to
restore the fragment state when the activity is
recreated. You can save the state during the
fragment's onSaveInstanceState() callback
and restore it during either onCreate(),
onCreateView(), or onActivityCreated(). For
more information about saving state, see the
Activities document.
Three Type View (in our project)
I (Fragment) II (Layout View)
III (DialogFragment)
Three Type View (in our project)
● There's view all in the same Activity.
● View control by Activity.
● Every data transaction with controller
need to over the Activity as your
view's controller.
Three Type View (in our project)
View Type Control
Help Guide Page
I (Fragment)
Activity
Channel list Page
Program Info Page
Schedule Record Page
Schedule List Page
Startup Page
Play list Page
EPG Search
II (DialogFragment)Subtitle Subaudio
Parental Control
Error Message III (Layout View)
References web site
Android Develop Guide
Fragment: http://developer.android.com/guide/components/fragments.html
Supporting Multiple Screen: http://developer.android.
com/guide/practices/screens_support.html
Blog
Fragment中文: http://leybreeze.com/blog/?p=902
Merge: http://zhuyonghui116.blog.hexun.com.tw/49165333_d.html
Include: http://158067568.iteye.com/blog/932206

Weitere ähnliche Inhalte

Was ist angesagt?

android layouts
android layoutsandroid layouts
android layouts
Deepa Rani
 
android activity
android activityandroid activity
android activity
Deepa Rani
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
11prasoon
 

Was ist angesagt? (20)

Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Applets
AppletsApplets
Applets
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycle
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
android layouts
android layoutsandroid layouts
android layouts
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
android activity
android activityandroid activity
android activity
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Android resources
Android resourcesAndroid resources
Android resources
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 

Andere mochten auch

Short Intro to Android Fragments
Short Intro to Android FragmentsShort Intro to Android Fragments
Short Intro to Android Fragments
Jussi Pohjolainen
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb Highlights
Romain Guy
 
Fragments notes powerpoint
Fragments notes powerpointFragments notes powerpoint
Fragments notes powerpoint
ktyndall
 

Andere mochten auch (17)

Android App Development - 06 Fragments
Android App Development - 06 FragmentsAndroid App Development - 06 Fragments
Android App Development - 06 Fragments
 
Android - Working with Fragments
Android - Working with FragmentsAndroid - Working with Fragments
Android - Working with Fragments
 
Android Fragment-Awesome
Android Fragment-AwesomeAndroid Fragment-Awesome
Android Fragment-Awesome
 
Short Intro to Android Fragments
Short Intro to Android FragmentsShort Intro to Android Fragments
Short Intro to Android Fragments
 
Intro to Google TV
Intro to Google TVIntro to Google TV
Intro to Google TV
 
Mobile in a Nutshell
Mobile in a NutshellMobile in a Nutshell
Mobile in a Nutshell
 
Fragment debugging
Fragment debuggingFragment debugging
Fragment debugging
 
India’s 1st online Independence Day Celebration
India’s 1st online Independence Day CelebrationIndia’s 1st online Independence Day Celebration
India’s 1st online Independence Day Celebration
 
παιδεία, εκπαίδευση
παιδεία, εκπαίδευσηπαιδεία, εκπαίδευση
παιδεία, εκπαίδευση
 
Belief: learning about new problems from old things
Belief: learning about new problems from old thingsBelief: learning about new problems from old things
Belief: learning about new problems from old things
 
Susanna Hintsala, itsemääräämisoikeus käytännössä, Autismin talvipäivät 2017
Susanna Hintsala, itsemääräämisoikeus käytännössä, Autismin talvipäivät 2017Susanna Hintsala, itsemääräämisoikeus käytännössä, Autismin talvipäivät 2017
Susanna Hintsala, itsemääräämisoikeus käytännössä, Autismin talvipäivät 2017
 
Petaluma Community Guild Guild Glyphosate Forum — Krupnick: Green Alternative...
Petaluma Community Guild Guild Glyphosate Forum — Krupnick: Green Alternative...Petaluma Community Guild Guild Glyphosate Forum — Krupnick: Green Alternative...
Petaluma Community Guild Guild Glyphosate Forum — Krupnick: Green Alternative...
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb Highlights
 
Judith Gould, autismikirjon naisten ja tyttöjen diagnosointi, Autismin talvip...
Judith Gould, autismikirjon naisten ja tyttöjen diagnosointi, Autismin talvip...Judith Gould, autismikirjon naisten ja tyttöjen diagnosointi, Autismin talvip...
Judith Gould, autismikirjon naisten ja tyttöjen diagnosointi, Autismin talvip...
 
Fragments notes powerpoint
Fragments notes powerpointFragments notes powerpoint
Fragments notes powerpoint
 
[Android] PLAYING WITH FRAGMENT
[Android] PLAYING WITH FRAGMENT[Android] PLAYING WITH FRAGMENT
[Android] PLAYING WITH FRAGMENT
 
Bt1 2015
Bt1 2015Bt1 2015
Bt1 2015
 

Ähnlich wie Android Fragment

Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
DHIRAJ PRAVIN
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
ShantanuDharekar
 
Fragmentation in android
Fragmentation in android Fragmentation in android
Fragmentation in android
Esraa El Ghoul
 

Ähnlich wie Android Fragment (20)

Android development session 4 - Fragments
Android development   session 4 - FragmentsAndroid development   session 4 - Fragments
Android development session 4 - Fragments
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Fragments In Android
Fragments In AndroidFragments In Android
Fragments In Android
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
 
fragments-activity.pptx
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Tk2323 lecture 6 fragment (new)
Tk2323 lecture 6   fragment (new)Tk2323 lecture 6   fragment (new)
Tk2323 lecture 6 fragment (new)
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
 
Fragments
FragmentsFragments
Fragments
 
深入淺出談Fragment
深入淺出談Fragment深入淺出談Fragment
深入淺出談Fragment
 
Lecture #4 activities & fragments
Lecture #4  activities & fragmentsLecture #4  activities & fragments
Lecture #4 activities & fragments
 
Android
AndroidAndroid
Android
 
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)
 
Lab3-Android
Lab3-AndroidLab3-Android
Lab3-Android
 
Fragmentation in android
Fragmentation in android Fragmentation in android
Fragmentation in android
 

Mehr von Kan-Han (John) Lu

Mehr von Kan-Han (John) Lu (20)

Dagger for android
Dagger for androidDagger for android
Dagger for android
 
Android develop guideline
Android develop guidelineAndroid develop guideline
Android develop guideline
 
Working process and git branch strategy
Working process and git branch strategyWorking process and git branch strategy
Working process and git branch strategy
 
Deep neural network for youtube recommendations
Deep neural network for youtube recommendationsDeep neural network for youtube recommendations
Deep neural network for youtube recommendations
 
Android testing part i
Android testing part iAndroid testing part i
Android testing part i
 
Cuda project paper
Cuda project paperCuda project paper
Cuda project paper
 
Twitter as a personalizable information service ii
Twitter as a personalizable information service iiTwitter as a personalizable information service ii
Twitter as a personalizable information service ii
 
Multimedia data minig and analytics sentiment analysis using social multimedia
Multimedia data minig and analytics sentiment analysis using social multimediaMultimedia data minig and analytics sentiment analysis using social multimedia
Multimedia data minig and analytics sentiment analysis using social multimedia
 
Android IPC: Binder
Android IPC: BinderAndroid IPC: Binder
Android IPC: Binder
 
ARM: Trusted Zone on Android
ARM: Trusted Zone on AndroidARM: Trusted Zone on Android
ARM: Trusted Zone on Android
 
Android Training - Card Style
Android Training - Card StyleAndroid Training - Card Style
Android Training - Card Style
 
Android Training - View Pager
Android Training - View PagerAndroid Training - View Pager
Android Training - View Pager
 
Android Training - Sliding Menu
Android Training - Sliding MenuAndroid Training - Sliding Menu
Android Training - Sliding Menu
 
Android Training - Pull to Refresh
Android Training - Pull to RefreshAndroid Training - Pull to Refresh
Android Training - Pull to Refresh
 
Java: Exception Handling
Java: Exception HandlingJava: Exception Handling
Java: Exception Handling
 
Dynamic Proxy by Java
Dynamic Proxy by JavaDynamic Proxy by Java
Dynamic Proxy by Java
 
Code analyzer: FindBugs and PMD
Code analyzer: FindBugs and PMDCode analyzer: FindBugs and PMD
Code analyzer: FindBugs and PMD
 
Android UI System
Android UI SystemAndroid UI System
Android UI System
 
Android Training - Content Sharing
Android Training - Content SharingAndroid Training - Content Sharing
Android Training - Content Sharing
 
Android Training - Action Bar
Android Training - Action BarAndroid Training - Action Bar
Android Training - Action Bar
 

Kürzlich hochgeladen

Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
Sérgio Sacani
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
PirithiRaju
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
Areesha Ahmad
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
gindu3009
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
RohitNehra6
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Sérgio Sacani
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Sérgio Sacani
 

Kürzlich hochgeladen (20)

Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questions
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 

Android Fragment

  • 2. Fragment A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities). A fragment must always be embedded in an activity and the fragment's lifecycle is directly affected by the host activity's lifecycle. For example, when the activity is paused, so are all fragments in it, and when the activity is destroyed, so are all fragments. However, while an activity is running (it is in the resumed lifecycle state), you can manipulate each fragment independently, such as add or remove them. When you perform such a fragment transaction, you can also add it to a back stack that's managed by the activity—each back stack entry in the activity is a record of the fragment transaction that occurred. The back stack allows the user to reverse a fragment transaction (navigate backwards), by pressing the Back button.
  • 3. Design Philosophy For example—to continue with the news application example—the application can embed two fragments in Activity A, when running on a tablet-sized device. However, on a handset-sized screen, there's not enough room for both fragments, so Activity A includes only the fragment for the list of articles, and when the user selects an article, it starts Activity B, which includes the second fragment to read the article. Thus, the application supports both tablets and handsets by reusing fragments in different combinations, as illustrated in figure 1.
  • 4. Creating a Fragment To create a fragment, you must create a subclass of Fragment (or an existing subclass of it). The Fragment class has code that looks a lot like an Activity. It contains callback methods similar to an activity, such as onCreate(), onStart(), onPause(), and onStop(). In fact, if you're converting an existing Android application to use fragments, you might simply move code from your activity's callback methods into the respective callback methods of your fragment.
  • 5. Handling the Fragment Lifecycle Also like an activity, you can retain the state of a fragment using a Bundle, in case the activity's process is killed and you need to restore the fragment state when the activity is recreated. You can save the state during the fragment's onSaveInstanceState() callback and restore it during either onCreate(), onCreateView(), or onActivityCreated(). For more information about saving state, see the Activities document.
  • 6. Three Type View (in our project) I (Fragment) II (Layout View) III (DialogFragment)
  • 7. Three Type View (in our project) ● There's view all in the same Activity. ● View control by Activity. ● Every data transaction with controller need to over the Activity as your view's controller.
  • 8. Three Type View (in our project) View Type Control Help Guide Page I (Fragment) Activity Channel list Page Program Info Page Schedule Record Page Schedule List Page Startup Page Play list Page EPG Search II (DialogFragment)Subtitle Subaudio Parental Control Error Message III (Layout View)
  • 9. References web site Android Develop Guide Fragment: http://developer.android.com/guide/components/fragments.html Supporting Multiple Screen: http://developer.android. com/guide/practices/screens_support.html Blog Fragment中文: http://leybreeze.com/blog/?p=902 Merge: http://zhuyonghui116.blog.hexun.com.tw/49165333_d.html Include: http://158067568.iteye.com/blog/932206