RadioButton
Class Structure:
RadioButton is a good understanding of the single-choice button in Web development. It should be noted that we need to set the same name for the single-choice button in Web development. Android development here, we need to put two or more RadioButton in a RadioGroup.
Practical drills:
1. How to set the alignment of RadioButton:
Android: orientation has the following values: vertical and horizontal.
Vertical:
<RadioGroup android: id = "@ + id/raGroup01"
Android: layout_width = "fill_parent" android: layout_height = "wrap_content"
Android: orientation = "vertical">
<RadioButton android: id = "@ + id/raBtn01" android: text = "male"/>
<RadioButton android: id = "@ + id/raBtn02" android: text = ""/>
</RadioGroup>
Effect:
Level:
<RadioGroup android: id = "@ + id/raGroup02"
Android: layout_width = "fill_parent" android: layout_height = "wrap_content"
Android: orientation = "horizontal">
<RadioButton android: id = "@ + id/rautf" android: text = "UTF"/>
<RadioButton android: id = "@ + id/ragbk" android: text = "GBK"/>
</RadioGroup>
Effect:
2. How to Set RadioButton to select
Android: checkedButton = "@ + id/rautf"
<RadioGroup android: id = "@ + id/raGroup02"
Android: layout_width = "fill_parent" android: layout_height = "wrap_content"
Android: orientation = "horizontal"
Android: checkedButton = "@ + id/rautf">
<RadioButton android: id = "@ + id/rautf" android: text = "UTF"/>
<RadioButton android: id = "@ + id/ragbk" android: text = "GBK"/>
</RadioGroup>
Effect:
Add listener:
RadioButton01 = (RadioButton) findViewById (R. id. raBtn01 );
RadioButton01.setOnClickListener (new OnClickListener (){
Public void onClick (View v ){
String text = radioButton01.getText (). toString ();
System. out. println (text );
}
});
CheckBox
Class Structure:
Instance:
<TextView android: layout_width = "fill_parent"
Android: layout_height = "wrap_content" android: text = "hobbies"/>
<CheckBox android: id = "@ + id/chckBox01" android: text = "Sports"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"/>
<CheckBox android: id = "@ + id/chckBox02" android: text = "Literature"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: checked = "true"/>
Effect:
Add listener registration event for CheckBox
CheckBox01.setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View v ){
System. out. println (checkBox01.getText (). toString ());
}
});
From: jiahui524 Column