The
previous app
had two separate objects,
a
Fragment
and a
View
.
It was an awkward arrangement because the
View
’s
Path
was actually inside the
Fragment
.
The
View
had to peer into the
Fragment
to see its own
Path
.
In this app,
the drawing code that used to be in the separate
View
object has been moved into the
Fragment
:
code follows fields
(or as we say in C++,
code follows data members.)
A fragment is often used to draw
one pane
of an
Activity
’s
user interface.
This Activity’s user interface consists of only one pane.
EtchActivity.java
:
radically simpler.EtchFragment.java
main.xml
:
the
f
in
fragment
must be lowercase.AndroidManifest.xml
:
untouched.
Another example of a
Fragment
that creates its own user interface with
onCreateView
.