Some of the switches in Android

Source: Internet
Author: User

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

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.