[Android beginners] 4. RadioButton & amp; CheckBox, androidradiobutton

Source: Internet
Author: User

[Android beginners] 4. RadioButton & CheckBox, androidradiobutton
Start Android

Today I learned about the functions and usage of Single-choice buttons and multiple-choice buttons.

The main purpose is to be more familiar with the control operation methods and common listeners.

1. Basic concepts of multiple choice buttons (CheckBox) 2. <CheckBox/> listeners with CheckBox3, OnClickListener, and OnCheckedChangeListener 1. Use the <CheckBox/> label in the XML file, you can create a CheckBox control in the Activity. 2. Use the CheckBox object in the code to indicate that common CheckBox methods include setOnCheckedChangeListener (), setOnClickListener (), setChecked (), getId (), and so on... 3. A listener of OnClickListener and OnCheckedChangeListener can be bound to multiple control objects OnClickListener OnClick (View v). Its parameter is the object that triggers the listener; OnCheckChangeListener's OnCheckedChanged (CompoundButton buttonView, boolean isChecked). The first parameter is the object that triggers the listener. The second parameter is the state of the object at this time. 1. Basic concepts of a radio button (RadioButton) one group of radio buttons can only be selected. 2. RadioGroup and RadioButton represent a group, and the latter is one of them. 3. The OnClickListener and OnCheckedChangeListener listeners are used to listen to the status of a Single-choice button group. 1) XML file: <RadioButton/> & <RadioGroup/> 2) code: RadioButton & RadioGroup 3) The OnClickListener and OnCheckedChangeListener listeners are usually operated in a way similar to multiple-choice button controls .. Finally, I found that I do not have the XML foundation. I still want to learn it. Who told me to switch from EE to CS...
How does android add four horizontal bars of RadioButton and reduce the size?

Add a property to RadioGroup: android: orientation =

In Android, how does one use RadioButton to set a four-column 12-row single-choice table?

In a RadioGroup, The RadioButton layout can only be vertical or horizontal. To set it to multiple rows, you need to use multiple radiogroups, then, you can set multiple radiogroups to select only one RadioGroup at the same time, which is similar to a RadioGroup, but you can arrange the RadioButton in the group in a way similar to Table Styles.
The following code sets multiple radiogroups to have only one function at the same time:
Private Boolean changeGroup = false;
Public void onCheckedChanged (RadioGroup group, int checkedId ){
If (group! = Null & checkedId>-1 & changeGroup = false ){
If (group = frequencyGroup1 ){
ChangeGroup = true;
FrequencyGroup2.clearCheck ();
FrequencyGroup3.clearCheck ();
ChangeGroup = false;
} Else if (group = frequencyGroup2 ){
ChangeGroup = true;
FrequencyGroup1.clearCheck ();
FrequencyGroup3.clearCheck ();
ChangeGroup = false;
} Else if (group = frequencyGroup3 ){
ChangeGroup = true;
FrequencyGroup1.clearCheck ();
FrequencyGroup2.clearCheck ();
ChangeGroup = false;
}
}
}

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.