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; просмотров: 815;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.005 сек.