Android Chinese API (34) -- RadioGroup

Source: Internet
Author: User

 

Preface

This chapter is about android. widget. RadioGroup. The translation comes from "bear the brunt". Thanks again "bear the brunt "! Welcome to join in Android API Chinese translation, contact me over140@gmail.com.

 

Statement

You are welcome to repost, but please keep the original source of the article :)

Blog Garden: http://www.cnblogs.com/

Android Chinese translation group: http://www.cnblogs.com/over140/

 

Body

I. Structure

    Public class RadioGroup extends LinearLayout

 

Java. lang. Object

Android. view. View

Android. view. ViewGroup

Android. widget. LinearLayout

Android. widget. RadioGroup

Ii. Overview

    

This class is used to create a group of single-choice button groups that are mutually exclusive. If you select a button in the same single-choice button group, the selected status of other selected buttons in the group will be canceled.

In the initial state, all single-choice buttons are not checked. Although you cannot cancel the check status of a specific single-choice button, you can use a single-choice button group to remove the selected status, identifies the specified selection information based on the unique ID of the radio button in the XML layout file.

 

Iii. Internal class

Class RadioGroup. LayoutParams

When the child components of WRAP_CONTENT (Package content) do not specify the corresponding width and height in the XML file, you can use the default settings of the layout parameters.

 

Interface RadioGroup. OnCheckedChangeListener

Interface Class of the callback function to be called when the status of the selected button in the radio button group changes

 

Iv. Public Methods

Public void addView (View child, int index, ViewGroup. LayoutParams params)

Add a subview using the specified layout Parameter

Parameters

Child View

Position of the subview to be added to the index

Layout parameters of the Child view to be added for params

Public void check (int id)

If-1 is passed as the specified selection identifier to clear the check status of the radio button group, it is equivalent to calling the clearCheck () operation.

Parameters

Id: the unique identifier (id) of the radio button to be selected in this group)

See

GetCheckedRadioButtonId ()

ClearCheck ()

 

Public void clearCheck ()

The current selection status is cleared. When the selection status is cleared, all the radio buttons in the radio button group are deselected. getCheckedRadioButtonId () returns null.

See

Check (int)

GetCheckedRadioButtonId ()

 

Public RadioGroup. LayoutParams generateLayoutParams (AttributeSet attrs)

Returns a new layout parameter set based on the provided property set.

Parameters

Attrs is used to generate attributes of layout parameters.

Return Value

Returns an instance of ViewGroup. LayoutParams or its subclass.

 

Public int getCheckedRadioButtonId ()

Returns the ID of the selected radio button in the single-choice button group. If it is not selected,-1 is returned.

Return Value

Returns the ID of the selected radio button in the radio button group.

See

Check (int)

ClearCheck ()

 

Public void setOnCheckedChangeListener (RadioGroup. OnCheckedChangeListener listener)

Register a callback function to be called when the status of the selected button in this radio button group changes

Parameters

Listener: the callback function to be called when the status of the single-choice button is changed

Public void setOnHierarchyChangeListener (ViewGroup. OnHierarchyChangeListener listener)

Register a callback function to be called when the sub-content is added to or removed from the View

Parameters

The callback function to be called when the level of the listener changes

 

5. Protected Methods

Protected LinearLayout. LayoutParams generatedefalalayoutparams ()

When the layout is in the vertical direction, a set of layout parameters whose width is "fill parent element" (MATCH_PARENT) and height is "Package content" will be returned. If the layout is in the horizontal direction, returns a set of layout parameters whose width is "Package content" and whose height is "fill parent element ".

(Match_parent is fill_parent, public static final int FILL_PARENT/MATCH_PARENT =-1)

Return Value

Returns a set of default layout parameters.

 

Protected void onFinishInflate ()

This method is called when the view is loaded from XML and the corresponding sub-view is added,

Even if the subclass overrides this method, make sure to call the method of the parent class (usually in the first sentence of the method) to complete the corresponding call parameters.

Return Value

Returns a set of default layout parameters.

 

Vi. Supplement

Article Link

Basic Android tutorial (7)-comprehensive application of RadioGroup in a single option box

Android uidesign RadioGroup radio button usage

Android tips-you can guess the name has a picture! Apply RadionButton and RadionGroup (with source keys)

Sample Code

      

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.