Let's power up Android Studio and get ready to dig a little deeper into the palette. While we are waiting for it to boot up, let's have a quick object recap, especially using objects from our UI layout.
We know that when we call setContentView
in the onCreate
method, Android inflates all the widgets and layouts and turns them into real Java objects on the heap.
We know that to use a widget from the heap, we must first declare an object of the correct type and then use it to get a reference to the UI widget object on the heap using its unique id
property. For example, we get a reference to TextView
with an id
property of txtTitle
and assign it to a new object called myTextView
like this:
// Grab a reference to an object on the heap TextView myTextView = (TextView) findViewById(R.id.txtTitle);
Now, using our myTextView
instance variable, we can do anything that the TextView
class was designed to do. For example, we can set the text...