Java Reference
In-Depth Information
Note
AnimationDrawable
indirectly extends the abstract
an-
droid.graphics.drawable.Drawable
class, which is a general abstraction
for a
drawable
, something that can be drawn (e.g., an image).
All the app's work takes place in
Java7MeetsAndroid
's overriding
onCreate(Bundle)
method:noothermethodsarerequired,whichhelpstokeepthis
app simple.
onCreate(Bundle)
first invokes its same-named superclass method, a rule that
must be followed by all overriding activity methods.
This method then executes
setContentView(R.layout.main)
to establish
the app's user interface.
R.layout.main
is an identifier (ID) for an application re-
source, which resides in a separate file. You interpret this ID as follows:
•
R
isthenameofaclassthat'sgenerated(bythe
aapt
tool)whentheappisbe-
ing built. This class is named
R
because its content identifies various kinds of
application resources (e.g., layouts, images, strings, and colors).
•
layout
isthenameofaclassthat'snestedwithin
R
.Allapplicationresources
whoseIDsarestoredinthisclassdescribespecificlayoutresources.Eachkind
ofapplicationresourceisassociatedwithanestedclassthat'snamedinasimilar
fashion. For example,
string
identifies string resources.
•
main
isthenameofan
int
constantdeclaredwithin
layout
.Thisresource
ID identifies the main layout resource. Specifically,
main
refers to a
main.xml
file that stores the main activity's layout information.
main
is
Java7MeetsAndroid
's only layout resource.
R.layout.main
is passed to
Activity
's
void setContentView(int
layoutResID)
methodtotellAndroidtocreateauserinterfacescreenusingthelay-
outinformationstoredin
main.xml
.Behindthescenes,Androidcreatestheuserinter-
facecomponentsdescribedin
main.xml
andpositionsthemonthescreenasspecified
by
main.xml
's layout data.
The screen is based on
views
(abstractions of user interface components) and
view
groups
(views that group related user interface components). Views are instances of
classes that subclass the
android.view.View
class and are analogous to AWT/
Swing components. View groups are instances of classes that subclass the abstract
android.view.ViewGroup
class and are analogous to AWT/Swing containers.
Android refers to specific views (e.g., buttons or spinners) as
widgets
.