Android ApiDemos example resolution (186): Views-& gt; Radio Group

Source: Internet
Author: User

RadioGroup is used to manage a set of Radio buttons. RadioButton is a single-choice Button. Only one RadioButton in the same group can be selected. In the preceding example, the Android ApiDemos sample is parsed (107): Views-> Controls-> 1. Light Theme.

Using RadioGroup is very simple. In XML, use RadioGroup as the Container of RadioButton:

<RadioGroup
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: orientation = "vertical"
Android: checkedButton = "@ + id/lunch"
Android: id = "@ + id/menu">
<RadioButton
Android: text = "@ string/radio_group_1_breakfast"
Android: id = "@ + id/breakfast"
/>
<RadioButton
Android: text = "@ string/radio_group_1_lunch"
Android: id = "@ id/lunch"/>
<RadioButton
Android: text = "@ string/radio_group_1_dinner"
Android: id = "@ + id/dinner"/>
<RadioButton
Android: text = "@ string/radio_group_typesall"
Android: id = "@ + id/all"/>
<TextView
Android: text = "@ string/radio_group_1_selection"
Android: id = "@ + id/choice"/>
</RadioGroup>

In the code, you can dynamically Add a View (such as RadioButton) to a RadioGroup:


[Java]
// Test adding a radio button programmatically
RadioButton newRadioButton = new RadioButton (this );
NewRadioButton. setText (R. string. radio_group_snack );
NewRadioButton. setId (R. id. snack );
LinearLayout. LayoutParams layoutParams
= New RadioGroup. LayoutParams (
RadioGroup. LayoutParams. WRAP_CONTENT,
RadioGroup. LayoutParams. WRAP_CONTENT );
MRadioGroup. addView (newRadioButton, 0, layoutParams );

// Test adding a radio button programmatically
RadioButton newRadioButton = new RadioButton (this );
NewRadioButton. setText (R. string. radio_group_snack );
NewRadioButton. setId (R. id. snack );
LinearLayout. LayoutParams layoutParams
= New RadioGroup. LayoutParams (
RadioGroup. LayoutParams. WRAP_CONTENT,
RadioGroup. LayoutParams. WRAP_CONTENT );
MRadioGroup. addView (newRadioButton, 0, layoutParams );

 

 

 


 

Related Article

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.