Introduction to fragments in android

praweshsth1 5,828 views 14 slides Oct 15, 2012
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

Introduction to fragments in android by Ritesh Bhattarai


Slide Content

An Introduction To
Fragments In Android
By: Ritesh Bhattarai
(reetesh.com.np)
Date: 13th October, 2012

What is a fragment?
A fragment is, as the name suggests, a chunk
of user interface with its own lifecycle which
must exist within an activity.
Multiple fragments can be used in a single
activity to form a multi-pane UI or reuse a
fragment in multiple activities.

Advantages of fragments
•It can modularize a single activity into
smaller units of UI, making it more flexible
and easier to manage.
•A fragment can exist without a UI screen
and act as an invisible worker for the activity.
•A fragment can be reused with multiple
activities.
•A fragment lets us maintain a "back-stack" of
its state.

Implementation in different screens

Implementations in paged layouts

Writing Fragment Layout
A fragment layout is similar to an activity layout.

Writing A Basic Fragment Class

Including Fragment Into Main Layout

Writing Main Activity Class

Fragment Types
ListFragment
DialogFragment
Custom Fragment (e.g Grid)

Compatibility
You can download the compatibility package using the Android
SDK Manager as shown below.

Compatibility (contd.)
To use the compatibility package, you must add
it to your project and include in the build path.
This can be done by Right clicking your Android
project-> Selecting Android Tools-> Add
compatibility Library.

Resources
API Guide
http://developer.android.com/guide/components/fragments.html
Tutorials
https://github.com/posco2k8/fragment_basic_tutorial
https://github.com/posco2k8/fragment_tabs_tutorial
Examples
https://github.com/jrgleason/android-fragments-example

Thank You