Introduction to fragments in android

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

description

Introduction to fragments in android by Ritesh Bhattarai

Transcript of Introduction to fragments in android

Page 1: Introduction to fragments in android

An Introduction To Fragments In Android

By: Ritesh Bhattarai(reetesh.com.np)

Date: 13th October, 2012

Page 2: Introduction to fragments in android

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.

Page 3: Introduction to fragments in android

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.

Page 4: Introduction to fragments in android

Implementation in different screens

Page 5: Introduction to fragments in android

Implementations in paged layouts

Page 6: Introduction to fragments in android

Writing Fragment Layout

A fragment layout is similar to an activity layout.

Page 7: Introduction to fragments in android

Writing A Basic Fragment Class

Page 8: Introduction to fragments in android

Including Fragment Into Main Layout

Page 9: Introduction to fragments in android

Writing Main Activity Class

Page 10: Introduction to fragments in android

Fragment Types

ListFragment

DialogFragment

Custom Fragment (e.g Grid)

Page 11: Introduction to fragments in android

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

Page 12: Introduction to fragments in android

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.

Page 13: Introduction to fragments in android

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

Page 14: Introduction to fragments in android

Thank You