鸿蒙OS开发文档 鸿蒙OS RadioContainer

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 11

RadioContainer

java.lang.Object
|---ohos.agp.components.Component
|---|---ohos.agp.components.ComponentContainer
|---|---|---ohos.agp.components.DirectionalLayout
|---|---|---|---ohos.agp.components.RadioContainer

public class RadioContainer
extends DirectionalLayout

创建一组表示一系列独占选项的单选按钮。

选择单选组中的一个单选按钮将自动取消选择同一组中的其他单选按钮。 默认情况下,取消选择组中的所有单选按钮。 无法取消选择已选择的单选按钮,但可以清除单选组以取消该单选按钮的选中状态。

Since:

3

嵌套类摘要

修饰符和类型描述
static interfaceRadioContainer.CheckedStateChangedListener提供回调方法来处理单选按钮容器的更改事件。
从类 ohos.agp.components.Component 继承的嵌套类/接口
Component.BindStateChangedListener, Component.CanAcceptScrollListener, Component.ClickedListener, Component.ComponentStateChangedListener, Component.ContourRefreshedListener, Component.DefSpeechEventListener, Component.DoubleClickedListener, Component.DragFeedbackProvider, Component.DraggedListener, Component.DrawTask, Component.EditEventListener, Component.EstimateSizeListener, Component.EstimateSpec, Component.FadeEffectEnum, Component.FocusChangedListener, Component.ForwardHoverListener, Component.ForwardTouchListener, Component.GestureType, Component.HoverEventListener, Component.KeyEventListener, Component.LayoutDirection, Component.LayoutRefreshedListener, Component.LongClickedListener, Component.MeasureSpec, Component.MouseEventListener, Component.MousePointerStyleListener, Component.OnDragListener, Component.RotationEventListener, Component.ScaledListener, Component.ScrolledListener, Component.ShadowDevice, Component.ShadowMode, Component.ShadowSize, Component.SpeechEventListener, Component.TouchEventListener, Component.UnconsumedKeyEventListener, Component.VoiceEvent
从类 ohos.agp.components.ComponentContainer 继承的嵌套类/接口
ComponentContainer.ArrangeListener
从类 ohos.agp.components.DirectionalLayout 继承的嵌套类/接口
DirectionalLayout.LayoutConfig

字段摘要

修饰符和类型字段描述
static intINVALID_ID表示无效的 id。
protected RadioContainer.CheckedStateChangedListenermMarkListener指示单选组中单选按钮更改事件的侦听器。
从类 ohos.agp.components.Component 继承的字段
ACCESSIBILITY_ADAPTABLE, ACCESSIBILITY_DISABLE, ACCESSIBILITY_ENABLE, AXIS_X, AXIS_Y, CONTOUR_BACKGROUND, CONTOUR_BORDER, CONTOUR_PADDING_BORDER, DEFAULT_SCALE, DRAG_DOWN, DRAG_HORIZONTAL, DRAG_HORIZONTAL_VERTICAL, DRAG_LEFT, DRAG_RIGHT, DRAG_UP, DRAG_VERTICAL, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED_CLEAR, EVENT_TYPE_COMPONENT_CLICKED, EVENT_TYPE_COMPONENT_FOCUSED, EVENT_TYPE_COMPONENT_LONG_CLICKED, EVENT_TYPE_COMPONENT_SCROLLED, EVENT_TYPE_COMPONENT_SELECTED, EVENT_TYPE_COMPONENT_TEXT_UPDATE, EVENT_TYPE_NOTICE, EVENT_TYPE_NOTIFICATION_STATE_UPDATE, EVENT_TYPE_TOAST_SHOW, EVENT_TYPE_WINDOW_STATE_UPDATE, FOCUS_ADAPTABLE, FOCUS_DISABLE, FOCUS_ENABLE, FOCUS_NEXT, FOCUS_PREVIOUS, FOCUS_SIDE_BOTTOM, FOCUS_SIDE_LEFT, FOCUS_SIDE_RIGHT, FOCUS_SIDE_TOP, HIDE, HORIZONTAL, ID_DEFAULT, INHERITED_MODE, INVISIBLE, mBackgroundElement, mCanvasForTaskOverContent, mCanvasForTaskUnderContent, mComponentParent, mContext, mDrawTaskOverContent, mDrawTaskUnderContent, mEstimateSizeListener, mForegroundElement, mForwardHoverListener, mHoverEventListener, mKeyEventListener, mMouseEventListener, mPosition, mRotationEventListener, mShadowElement, mUnconsumedKeyEventListener, OVAL_MODE, OVAL_SCROLL_BAR_MODE, POSITION_X_INDEX, POSITION_Y_INDEX, RECT_MODE, RECT_SCROLL_BAR_MODE, SCROLL_AUTO_STAGE, SCROLL_IDLE_STAGE, SCROLL_NORMAL_STAGE, UNSPECIFIED_SCROLL_BAR_MODE, VERTICAL, VISIBLE
从类 ohos.agp.components.ComponentContainer 继承的字段
FOCUS_CHILDREN_FIRST, FOCUS_CHILDREN_HIDE, FOCUS_PARENT_FIRST, mArrangeListener

构造函数摘要

构造函数描述
RadioContainer(Context context)用于使用默认属性集和样式创建 RadioContainer 实例的默认构造函数。
RadioContainer(Context context, AttrSet attrSet)用于在 XML 文件解析后使用指定的属性集和默认样式创建 RadioContainer 实例的构造函数。
RadioContainer(Context context, AttrSet attrSet, String styleName)用于在 XML 文件解析后使用指定的属性集和指定样式创建 RadioContainer 实例的构造函数。

方法总结

修饰符和类型方法描述
voidcancelMarks()清除单选组中所有单选按钮的选定状态。
RadioContainer.CheckedStateChangedListenergetMarkChangedListener()获取监听此 RadioContainer 中单选按钮更改事件的监听器。
intgetMarkedButtonId()获取单选组中选中单选按钮的ID。
voidmark(int id)选择其 ID 在参数中传递的单选按钮。
voidsetMarkChangedListener(RadioContainer.CheckedStateChangedListener listener)为单选容器中单选按钮的更改事件设置侦听器。
从类 ohos.agp.components.Component 继承的方法
addDrawTask, addDrawTask, addScrolledListener, announceAccessibility, arrange, bindCornerMark, callOnClick, canScroll, clearFocus, createAnimatorProperty, disableFadeEffect, draw, enableCornerMark, enableFadeEffect, enableSaveState, enableScrollBar, estimateSize, executeDoubleClick, executeLongClick, findFocus, findNextFocusableComponent, findRequestNextFocus, getAccessibility, getAccessibilityDescription, getAlpha, getAltitude, getBackgroundElement, getBaseLine, getBottom, getBoundaryFadeEffectBottomRate, getBoundaryFadeEffectLeftRate, getBoundaryFadeEffectRightRate, getBoundaryFadeEffectTopRate, getCenterZoomFactor, getCentralScrollMode, getClickedListener, getClipEnabled, getComponentDescription, getComponentMinSize, getComponentParent, getComponentPosition, getComponentSize, getComponentStateChangedListener, getComponentTreeObserver, getContentEnable, getContentPosition, getContentPositionX, getContentPositionY, getContext, getContour, getContourRefreshedListener, getCornerMark, getDragAcceptAngle, getDraggedListener, getEditEventListener, getEstimatedHeight, getEstimatedWidth, getFadeEffectBoundaryWidth, getFadeEffectColor, getFocusable, getFocusBorderEnable, getFocusBorderPadding, getFocusBorderRadius, getFocusBorderWidth, getForegroundElement, getForegroundGravity, getForwardHoverListener, getForwardTouchListener, getGesturePriority, getHeight, getHorizontalPadding, getHorizontalPosition, getHoverEventListener, getId, getKeyEventListener, getLayoutConfig, getLayoutDirection, getLayoutDirectionResolved, getLayoutRefreshedListener, getLeft, getLocationOnScreen, getMarginBottom, getMarginLeft, getMarginRight, getMargins, getMarginsLeftAndRight, getMarginsTopAndBottom, getMarginTop, getMatrix, getMinHeight, getMinWidth, getMode, getModeResolved, getMouseEventListener, getMousePointerStyleListener, getName, getPadding, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPivot, getPivotX, getPivotY, getResourceManager, getRight, getRotation, getRotationEventListener, getRotationSensitivity, getScale, getScaledListener, getScaleX, getScaleY, getScrollbarBackgroundColor, getScrollbarColor, getScrollbarFadingDelay, getScrollbarFadingDuration, getScrollBarMode, getScrollbarRadius, getScrollbarRoundRect, getScrollbarStartAngle, getScrollbarSweepAngle, getScrollbarThickness, getScrollState, getScrollValue, getSelfVisibleRect, getShadowColor, getSpeechEventListener, getTag, getTop, getTouchEventListener, getTransitionSymbol, getTranslation, getTranslationX, getTranslationY, getTranslationZ, getUserNextFocus, getVerticalPadding, getVerticalPosition, getVisibility, getVisibleRectOnScreen, getWidth, getWindowVisibleRect, hasFocus, hasFocusedEffect, hasOverlaps, hideFocusBorder, invalidate, isBoundaryFadeEffectEnable, isBoundToWindow, isClickable, isClipToContourEnabled, isComponentDisplayed, isEnabled, isFadeEffected, isFocusable, isFocused, isIdentityMatrix, isLongClickOn, isPressed, isRtl, isSaveStateEnabled, isScrollbarFadingOn, isScrollBarOn, isScrollbarOverlapEnabled, isSelected, isSoundEnable, isTouchFocusable, isVibrationEffectEnabled, notifyAccessibility, onAttributeConfigChanged, onRestoreState, onRtlChanged, onSaveState, performScale, playSound, postLayout, refreshContour, release, removeBindStateChangedListener, removeScrolledListener, requestFocus, requestForceForwardTouchEvent, restoreComponentTreeState, saveComponentTreeState, scrollBy, scrollTo, setAccessibility, setAccessibilityDescription, setAlpha, setAltitude, setBackground, setBindStateChangedListener, setBottom, setBoundaryFadeEffectEnable, setCanAcceptScrollListener, setCenterZoomFactor, setCentralScrollMode, setClickable, setClickedListener, setClipEnabled, setClipToContourEnabled, setComponentDescription, setComponentMinSize, setComponentPosition, setComponentPosition, setComponentSize, setComponentStateChangedListener, setContentEnable, setContentPosition, setContentPositionX, setContentPositionY, setContour, setContourRefreshedListener, setDoubleClickedListener, setDragAcceptAngle, setDraggedListener, setEditEventListener, setEnabled, setEstimatedSize, setEstimateSizeListener, setFadeEffectBoundaryWidth, setFadeEffectColor, setFocusable, setFocusBorderEnable, setFocusBorderPadding, setFocusBorderRadius, setFocusBorderRadius, setFocusBorderWidth, setFocusChangedListener, setFocusedEffect, setForeground, setForegroundGravity, setForwardHoverListener, setForwardTouchListener, setGesturePriority, setHeight, setHorizontalPadding, setHorizontalPosition, setHoverEventListener, setId, setKeyEventListener, setLayoutConfig, setLayoutDirection, setLayoutRefreshedListener, setLeft, setLongClickable, setLongClickedListener, setMarginBottom, setMarginLeft, setMarginRight, setMarginsLeftAndRight, setMarginsTopAndBottom, setMarginTop, setMinHeight, setMinWidth, setMode, setMouseEventListener, setMousePointerStyleListener, setName, setOnDragListener, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRelative, setPaddingRight, setPaddingTop, setPivot, setPivot, setPivotX, setPivotY, setPosition, setPositionX, setPositionY, setPressState, setRight, setRotation, setRotationEventListener, setRotationSensitivity, setScale, setScaledListener, setScaleX, setScaleY, setScrollbarBackgroundColor, setScrollbarColor, setScrollbarFadingDelay, setScrollbarFadingDuration, setScrollbarFadingEnabled, setScrollBarMode, setScrollbarOverlapEnabled, setScrollbarRadius, setScrollbarRoundRect, setScrollbarStartAngle, setScrollbarSweepAngle, setScrollbarThickness, setScrolledListener, setSelected, setShadowColor, setShadowStyle, setSoundEnable, setSpeechEventListener, setTag, setTop, setTouchEventListener, setTouchFocusable, setTransitionSymbol, setTranslation, setTranslationX, setTranslationY, setTranslationZ, setUnconsumedKeyEventListener, setUserNextFocus, setVerticalPadding, setVerticalPosition, setVibrationEffectEnabled, setVisibility, setWidth, showFocusBorder, simulateClick, simulateDrag, startDragAndDrop, subscribeVoiceEvents, unsubscribeVoiceEvents
从类 ohos.agp.components.ComponentContainer 继承的方法
addComponent, addComponent, addComponent, addComponent, addComponent, dispatchRestoreState, dispatchSaveState, findComponentById, findComponentHolderById, getAutoLayout, getChildCount, getChildIndex, getComponentAt, getComponentTransition, getFocusOrder, getLayoutManager, informConfigurationChanged, isClipToChildBoundsEnabled, isClipToPaddingBoundsEnabled, isTouchEventSplitable, moveChildToFront, onDrag, removeAllComponents, removeComponent, removeComponentAt, removeComponentById, removeComponents, setArrangeListener, setAutoLayout, setAutoLayout, setClipToChildBoundsEnabled, setClipToPaddingBoundsEnabled, setComponentTransition, setFocusOrder, setLayoutManager, setTouchEventSplitable
从接口 ohos.agp.components.ComponentParent 继承的方法
getComponentParent, postLayout
从类 ohos.agp.components.DirectionalLayout 继承的方法
createLayoutConfig, getAlignment, getOrientation, getTotalWeight, isLayoutBaselined, setAlignment, setLayoutBaselined, setOrientation, setTotalWeight, verifyLayoutConfig
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

字段详细信息

INVALID_ID

public static final int INVALID_ID

表示无效的 id。

使用此值可清除单选组中所有单选按钮的选定状态。 见标记(int)。

mMarkListener

protected RadioContainer.CheckedStateChangedListener mMarkListener

指示单选组中单选按钮更改事件的侦听器。

构造函数详细信息

RadioContainer

public RadioContainer(Context context)

用于使用默认属性集和样式创建 RadioContainer 实例的默认构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。

RadioContainer

public RadioContainer(Context context, AttrSet attrSet)

用于在 XML 文件解析后使用指定的属性集和默认样式创建 RadioContainer 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。

RadioContainer

public RadioContainer(Context context, AttrSet attrSet, String styleName)

用于在 XML 文件解析后使用指定的属性集和指定样式创建 RadioContainer 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。
styleName指示要使用的样式名称。

方法详情

mark

public void mark(int id)

选择其 ID 在参数中传递的单选按钮。

单选组中的每个单选按钮都有一个 ID,范围从 0 到 n-1。 单选按钮 ID 与 Component#getId() 中的不同。 如果单选按钮 ID 为 INVALID_ID,则该组中所有单选按钮的选中状态都是清除的,相当于 cancelMarks()。

参数:

参数名称参数描述
id指示要选择的单选按钮的 ID。

Throws:

Throw名称Throw描述
IllegalArgumentException如果参数值小于 INVALID_ID,则引发此异常。

Since:

4

getMarkedButtonId

public int getMarkedButtonId()

获取单选组中选中单选按钮的ID。

ID 范围从 0 到 n-1。 如果取消选择单选组中的所有按钮,则 ID 为 INVALID_ID。

返回:

返回所选单选按钮的 ID。

Since:

4

cancelMarks

public void cancelMarks()

清除单选组中所有单选按钮的选定状态。

这样,单选组中的所有按钮都被取消选择。

Since:

4

setMarkChangedListener

public void setMarkChangedListener(RadioContainer.CheckedStateChangedListener listener)

为单选容器中单选按钮的更改事件设置侦听器。

当单选按钮的状态从取消选中变为选中时使用此方法,反之亦然。 它通知单选按钮的更改事件并调用 RadioContainer.CheckedStateChangedListener#onCheckedChanged(RadioContainer, int) 来处理更改事件。

参数:

参数名称参数描述
listener指示单选组中单选按钮更改事件的侦听器。

Since:

4

getMarkChangedListener

public RadioContainer.CheckedStateChangedListener getMarkChangedListener()

获取监听此 RadioContainer 中单选按钮更改事件的监听器。

返回:

返回获取的监听器。

Since:

4