Radiobutton consists of two parts: radiobutton and radiogroup. radiogroup is a single-choice combo box that can hold multiple radiobutton containers. radiobutton can be selected if no radiogroup exists. When multiple radiobutton instances are included in a radiogroup, only one radiobutton instance can be selected. Use setoncheckedchangelistener to listen to the radio button
Radiogroup attributes:
Radiogroup. getcheckedradiobuttonid (); -- get the ID of the selected button
Radiogroup. clearcheck (); // --- clear the selected state
Radiogroup. check (int id); // --- set this option to the selected status through the input option ID. If-1 is passed as the specified selection identifier, the check status of the single-choice button group is cleared, it is equivalent to calling the clearcheck () operation.
Setoncheckedchangelistener (radiogroup. oncheckedchangelistener listener); // a callback function to be called when the status of the single-choice button in the single-choice button group is changed
Addview (view child, int index, viewgroup. layoutparams Params); // --- add a subview using the specified layout Parameter
// Parameter child: the Child View index to be added the child view location Params the child view layout parameter to be added
Radiobutton. gettext (); // obtain the value of a single response
// In addition, the checked attribute of radiobutton is set to true. The check (ID) method of radiobutton is called in the Code and the oncheckedchanged event is not triggered.
The relationship between radiobutton and radiogroup:
1. radiobutton indicates a single circle, while radiogroup is a container that can hold multiple radiobutton.
2. Only one radiobutton in each radiogroup can be selected.
3. radiobutton in different radiogroups is irrelevant. That is, if one of group A is selected, one of group B can still be selected.
4. In most cases, a radiogroup contains at least two radiobutton
5. In most cases, radiobutton in a radiogroup will be selected by default. We recommend that you place it in the starting position of the radiogroup.
Case study: http://my.oschina.net/amigos/blog/59261