A (175)

(Tuis.) #1

254 CHAPTER 7: Making Apps Interactive: Intents, Event Handling, and Menus


Before we add our event handling code that will transfer the EditText object data into the Galaxy
object data field, we will first need to go into our MainActivity.java Activity subclass and make our
Galaxy object visible!


Making the Galaxy Object Accessible: Using The static Keyword


The Java static keyword, which we learned about in Chapter 5, will make an object accessible
across your Android application. Open your MainActivity.java class in the Eclipse ADT central editing
pane and add a static keyword before the Galaxy milkyWay object declaration and construction line
of code. This is the very first line of code in the class, as can be seen at the top of Figure 7 -3 8.


Figure 7-37. Mouse-over the View.OnClickListener error highlight, and select the Add unimplemented method option


Figure 7-38. Add the static keyword in front of the Galaxy object named milkyWay in the MainActivity.java class

Free download pdf