Академический Документы
Профессиональный Документы
Культура Документы
What is a Fragment?
View 2 View 4
What is a Fragment?
Fragment 1 Fragment 2
Activity 1 Activity 1
What is a Fragment?
ACTIVITY
• Fragment is a chunk of UI. FRAGMENT 1 FRAGMENT 2
• It has its own Lifecycle.
• It can process its own events
• It can be added or removed
while the Activity runs.
• It was introduced in
Honeycomb API 11.
• You can use Fragments on
older devices using a Support
ListView ImageView
Library from 1.6 to 2.3
Why do you need Fragments ?
• Dialog boxes
How to make a Fragment ?
Fragment 1
Fragment Manager
Fragment 3
Fragment 2
Fragment Transactions
Fragement
Manager
Begin a transaction
begin
Add, remove, replace whatever fragments
you want Fragement A
commit
Inter-Fragment communication
design
• Don’t maintain direct references of fragments within each other
• Crete an interface that contains the method which will act as an event carrier
• Let the Activity implement the interface
• Let Fragment 1 use the interface to send messages
• Use the callback method in Activity to trigger changes in Fragment 2
interface FragmentManager
Activity
Fragment 1 Fragment 2
Questions ?