Android 11th Lesson--ui Checkbox

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.