16
Alaa Alsalehi Serve Me

Fragment me

  • Upload
    a-a

  • View
    454

  • Download
    2

Embed Size (px)

DESCRIPTION

Android lecture about fragment simple and easy talk

Citation preview

Page 1: Fragment me

Alaa Alsalehi

Serve Me

Page 2: Fragment me

https://play.google.com/store/apps/developer?id=ServeMe

Page 3: Fragment me

What is fragment?

Why fragment?

How to use fragment?

Lifecycle

Advanced usages

Page 4: Fragment me

A Fragment represents a behavior or a portion of user interface in an Activity.

Reusable component.◦ User interface

◦ Background worker

Page 5: Fragment me

Why fragment?

Page 6: Fragment me
Page 7: Fragment me
Page 8: Fragment me
Page 9: Fragment me
Page 10: Fragment me
Page 11: Fragment me
Page 12: Fragment me
Page 13: Fragment me

Add to layout file<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><fragment android:name="com.example.news.ArticleListFragment"

android:id="@+id/list"android:layout_weight="1"android:layout_width="0dp"android:layout_height="match_parent" />

<fragment android:name="com.example.news.ArticleReaderFragment"android:id="@+id/viewer"android:layout_weight="2"android:layout_width="0dp"android:layout_height="match_parent" />

</LinearLayout>

Page 14: Fragment me

Add it dynamically to activity using fragment manager

FragmentManager fragmentManager = getFragmentManager();FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();ExampleFragment fragment = new ExampleFragment();fragmentTransaction.add(R.id.fragment_container, fragment);fragmentTransaction.commit();

Page 15: Fragment me

Fragment represent sub-activity

On attach and on detach like view.

The other callback like activity.

Page 16: Fragment me

Non UI Fragment◦ Background worker

Not a service

Die when activity die

◦ Cache data

Backup and restore when configuration change