Turn the Radio Up

 

As with other implementations of radio buttons in other toolkits, Android’s radio buttons are two‑state, like checkboxes, but can be grouped such that only one radio button in the group can be checked at any time.

Like , inherits from , which in turn inherits from . Hence, all the standard properties for font face, style, color, etc., are available for controlling the look of radio buttons. Similarly, you can call on a to see if it is selected, to select it, and so on, like you can with a .

Most times, you will want to put your widgets inside of a . The indicates a set of radio buttons whose state is tied, meaning only one button out of the group can be selected at any time. If you assign an to your in your XML layout, you can access the group from your Java code and invoke:

• to check a specific radio button via its ID (e.g., )

• to clear all radio buttons, so none in the group are checked

• to get the ID of the currently‑checked radio button (or ‑1 if none are checked)

For example, from the sample application, here is an XML layout showing a wrapping a set of widgets:

 

Figure 6‑6 shows the result using the stock Android‑generated Java for the project and this layout.

Figure 6‑6. The RadioButtonDemo sample application

Note that the radio button group is initially set to be completely unchecked at the outset. To pre‑set one of the radio buttons to be checked, use either on the or on the from within your callback in your activity.

 

It’s Quite a View

 

All widgets, including the ones previously shown, extend View, and as such give all widgets an array of useful properties and methods beyond those already described.

 








Дата добавления: 2015-05-16; просмотров: 709;


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

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

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

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