SetContentView
This is the same we used earlier, passing it an instance of a subclass (in that case, a ). The Android‑built view, constructed from our layout, is accessed from that code‑generated class. All of the layouts are accessible under R.layout, keyed by the base name of the layout file – results in .
To access our identified widgets, use , passing in the numeric identifier of the widget in question. That numeric identifier was generated by Android in the class as (where something is the specific widget you are seeking). Those widgets are simply subclasses of , just like the instance we created in Chapter 4.
The Rest of the Story
In the original demo, the button’s face would show the current time, which would reflect when the button was last pushed (or when the activity was first shown, if the button had not yet been pushed).
Most of that logic still works, even in this revised demo (). However, rather than instantiating the Button in our activity’s callback, we can reference the one from the XML layout:
Package
Import
Import
Import
Import
Import
Public class extends
Implements
Public onCreate
Super onCreate
SetContentView
FindViewById
SetOnClickListener this
UpdateTime
Public onClick
UpdateTime
Private updateTime
Дата добавления: 2015-05-16; просмотров: 800;