CheckBox
Two states: Checked (true) and unchecked (false)
Property:
Android:id= "@+id/checkbox"
Android:checked= "False" whether the selected state
android:text= "Female"
New:
<checkbox android:id= "@+id/cb1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" an droid:text= "Basketball" android:checked= "false"/>
Specific implementation:
Private CheckBox CB;
Initialize the checkboxcb= (checkbox) Findviewbyid (R.ID.CB1);//By setting a CheckBox's Listener event to determine Checkboxcb.setoncheckedchangelistener ( New Compoundbutton.oncheckedchangelistener () {@Override public void oncheckedchanged (Compoundbutton Compoundbutton, Boolean b) {if (b) {Toast.maketext (mainactivity.this, "Hi~basketball", Toast.length_short). Show (); } }});
You can customize the checkbox style with the style
RadioButton and Radiogroup
It is not recommended to use standalone because it cannot be closed by itself when pressed
Radiogroup:
A collection of RadioButton that provides the use of multiple choices
Property:
android:orientation= "vertical" (vertical arrangement) or "horizontal" (horizontal arrangement)
Set the arrangement of the Radiogroup neutron class
New View:
<radiogroup android:id= "@+id/rg1" android:layout_width= "Wrap_ Content " android:layout_height=" Wrap_content " android:o rientation= "Horizontal" > <RadioButton android:id= "@+id/rb1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:checked= "true" android:text= "male" /> <radiobutton android:id= " @+id/rb2 " android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:text= "female" &nbSp;/></radiogroup>
Specific implementation:
Private Radiogroup RG;
Initialize radiogrouprg= (radiogroup) findviewbyid (R.ID.RG1);//Implement Listener event Rg.setoncheckedchangelistener (new radiogroup.oncheckedchangelistener () { @Override Public void oncheckedchanged (radiogroup radiogroup, int i) { //radioGroup Current Components //i Id switch (i) { of the selected item in the Radiogroup case R.id.rb1: toast.maketext (mainactivity.this, "You Choose Man ", toast.length_short). Show (); break; case r.id.rb2: &nbsP; toast.maketext ( mainactivity.this, "You choose woman", toast.length_short). Show (); break; } }});
RadioButton state changes in radiogroup can be monitored either through radiobutton or through Radiogroup
Some of the switches in Android