A (175)

(Tuis.) #1
588 CHAPTER 15: Developing for Android Wearable Devices

As you can see in Figure 15-45, if you type in the R.drawable part of the asset reference, and then
type a period inside of the .setBackgroundResource( ) method call’s parameter area, Eclipse will
show a helper dialog. This contains drawable assets that you have installed in the project thus far.
Double-click on the marstime:int - R.drawable option to complete your marsIcon ImageView
event-handling structure.
Copy the eight lines of code for the two marsIcon instantiation and event-handling structures, and
paste them three more times underneath this structure. Change “mars” to “earth,” “neptune,” and
“jupiter” in each of the three eight-line Java code structures, creating the earthIcon, neptuneIcon,
and jupiterIcon UI element Java code structures for the other three planet icons.
The four completed planet icon ImageView UI element code structures are shown in Figure 15-46,
and are error-free. All that you have to do is use the Run As ➤ Android Application menu sequence
and launch the AVD for the Neptune Pine. That way, you can test all four of the planet icons in the
corners of your app to make sure that they change the planet image.

Figure 15-45. Add the onTouch( ) handler method inside of the OnTouchListener( ) by calling .setBackgroundResource( )

Free download pdf