Common Base Empty components
6 CheckBox
check box is one of the common components, but although the development process in many places will use the check box, but not the original style provided by the Android system, similar to when we write HTML, the different browser provides the check box button is not the same, the compatibility is very poor, the general picture instead of camouflage. However, the function of the check box is the same regardless of the disguise style.
Components in Layout:
<CheckBox android:id= "@+id/cb1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:checked= "true" android:text= "Basketball"/> <checkbox android: Id= "@+id/cb2" android:layout_ Width= "Wrap_content" android: layout_height= "Wrap_content" &NBSP;&NBsp; android:text= "Baseball"/>
protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (R.layout.activity_main); // Get checkbox cb1 = (CheckBox) Findviewbyid (R.ID.CB1); cb2 = ( CheckBox) Findviewbyid (R.ID.CB2); // Register Event Listener for checkbox (the OnCheckedChanged method of this class is triggered when the check box is selected or checked to unchecked) Cbcheckedimpl impl = new cbcheckedimpl (); Cb1.setoncheckedchangelistener (Impl); Cb2.setoncheckedchangelistener (impl); } // activity Inner class, Implement the Android.widget.CompoundButton.OnCheckedChangeListener interface to implement the OnCheckedChanged method at the same time &NBSP;&NBSP;BTN represents a component that has a state change, Flag if checked for true, otherwise indicated as selected @Override public void oncheckedchanged ( Compoundbutton btn, boolean flag) { // TODO auto-generated method stub string rs = "Nothing"; rs = flag? " Select +btn.gettext (). ToString (): "Unchecked" +btn.gettext (). ToString (); toast.maketext ( Checkboxactivity.this,rs, toast.length_short). Show (); } }
Attention:
1) check box is used basically and radio buttons almost, The main thing is to remember the radio button implementation of the interface monitoring is Android.widget.RadioGroup.OnCheckedChangeListener, but the review button implementation of the monitoring is Android.widget.CompoundButton.OnCheckedC Hangelistener. Do not assume that the radio button and the check button are Compoundbutton subclasses, you should implement the same interface, in fact, because the radio button has the concept of a group, but the check button does not have the concept of a group.
The next section will learn about the UI
7 ProgressBar
8 ListView listactivity Simpleadapter
Android 11th Lesson--ui Checkbox