A (175)

(Tuis.) #1

206 CHAPTER 6: Android Screen Design: Writing to the Display Using Activity and View


Testing and Debugging your Application


Now let’s take a moment to use the Run As ➤ Android Application menu sequence, and we will
see if your UI design now displays the “Milky Way” text data value, assigned using Java code, rather
than the “My Galaxy” text data value assigned using XML markup using the constant.


As you can see in Figure 6-36, the code thus far in your transferDataValues( ) method is working as
expected, and the UI screen now displays the Galaxy object galaxyName variable’s data value in the
nameData TextView next to the “Galaxy Name:” labeling TextView.


Figure 6-36. Testing the HelloUniverse application in the Nexus One AVD emulator, and showing an app crash


The next six data TextView UI widgets need to display numeric values (integer, double, long, and so
forth) and so we can (and will) try to use the same code, and hope that Java will “cast” the numeric
values into text values for us.


The concept of “casting” in Java is a process where the Java programming environment (the
compiler) will auto-convert (cast) a data value from one format into another where it is logical and it
is able to do so. So we will try passing a numeric data value type into the .setText( ) method call in
the hope that the “type casting” (any actors out there?) will be done for us automatically. If not, then
you are about to get to utilize your LogCat tool!


Copy and paste the nameData.setText(milkyWay.galaxyName); line of code underneath itself
and change the nameData and galaxyName references to the solarData TextView reference and
galaxySolarSystems Galaxy object variable references, respectively.

Free download pdf