December 2013
Beginner
416 pages
12h 45m
English
In this section, you will write Java code inside an activity. You will obtain a TextView view that refers to the hello id that you added earlier in the /res/layout/activity_main.xml.
1. Open MainActivity.java, and add the following code at the bottom of the onCreate() method. This code finds the TextView with the id R.id.hello, which is a generated constant:
TextView hello = (TextView) findViewById(R.id.hello);
Note that you must call setContentView before calling findViewByID(). Otherwise, you will receive a runtime error.
2. Eclipse will put a wavy red line under TextView and display a Quick Fix pop-up box saying, “TextView cannot be resolved to a type.” Hover ...
Read now
Unlock full access