Java Reference
In-Depth Information
{
AnimationDrawable dukeAnimation;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView
dukeImage
=
(ImageView)
find-
ViewById(R.id.duke);
dukeImage.setBackgroundResource(R.drawable.duke_wave);
dukeAnimation
=
(AnimationDrawable)
dukeImage.getBackground();
final
Button
btnWave
=
(Button)
find-
ViewById(R.id.wave);
View.OnClickListener ocl;
ocl = new View.OnClickListener()
{
@Override
public void onClick(View v)
{
dukeAnimation.stop();
dukeAnimation.start();
}
};
btnWave.setOnClickListener(ocl);
}
}
Listing 12-3
begins with a package statement that names the package
(
ca.tutortutor.j7ma
) in which its
Java7MeetsAndroid
class is stored, fol-
lowedbyaseriesofimportstatementsthatimportvariousAndroidAPItypes.Thislist-
ing next describes the
Java7MeetsAndroid
class, which extends
Activity
.
Java7MeetsAndroid
first declares a
dukeAnimation
instance field of type
android.graphics.drawable.AnimationDrawable
. Objects of type
An-
imationDrawable
describeframe-by-frameanimations,inwhichthecurrentdraw-
able is replaced with the next drawable in the animation sequence.