202 CHAPTER 6: Android Screen Design: Writing to the Display Using Activity and View
Once this first line of code shows as being error-free, you can then copy it in its entirety and paste it,
six more times, underneath itself. Make sure to change the name variable and TextView ID reference
to be solar, habit, colony, pop, fleet, and ships, respectively, as can be seen in Figure 6-32.
Now you have the createUiTextViews( ) method coded, which instantiates all of your TextView
objects and also sets them to reference their XML definitions by using the findViewById( ) method
in conjunction with the appropriate resource area and ID value. You are now ready to create the
transferDataValues( ) method, which will take the data values out of your seven variables in your
milkyWay Galaxy object, and transfer those values into your seven TextView UI widgets, which you
designed to display those values in your UI screen design.
Creating the transferDataValues( ) Method
By modularizing your Galaxy and TextView object(s) set up into logical methods, your onCreate( )
method has a mere two lines of code, as you can see in Figure 6-33, instead of a dozen lines of
code. These method calls are logically named, so that anyone else who may need to read your code
will know precisely what you are doing!
Figure 6-32. Instantiate a nameData TextView; use the findViewById( ) method and Eclipse helper pop-up to configure