blob: a0fef7dafc6d8947f615fec3d28aab45157d3cef [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.widget;
18
19import android.content.Context;
20import android.util.AttributeSet;
Svetoslav Ganov76502592011-07-29 10:44:59 -070021import android.view.accessibility.AccessibilityEvent;
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -080022import android.view.accessibility.AccessibilityNodeInfo;
Svetoslav Ganov76502592011-07-29 10:44:59 -070023
24import com.android.internal.R;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26
27/**
28 * <p>
29 * A radio button is a two-states button that can be either checked or
30 * unchecked. When the radio button is unchecked, the user can press or click it
31 * to check it. However, contrary to a {@link android.widget.CheckBox}, a radio
32 * button cannot be unchecked by the user once checked.
33 * </p>
34 *
35 * <p>
36 * Radio buttons are normally used together in a
37 * {@link android.widget.RadioGroup}. When several radio buttons live inside
38 * a radio group, checking one radio button unchecks all the others.</p>
39 * </p>
40 *
Scott Main4c359b72012-07-24 15:51:27 -070041 * <p>See the <a href="{@docRoot}guide/topics/ui/controls/radiobutton.html">Radio Buttons</a>
42 * guide.</p>
Scott Main41ec6532010-08-19 16:57:07 -070043 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 * <p><strong>XML attributes</strong></p>
45 * <p>
46 * See {@link android.R.styleable#CompoundButton CompoundButton Attributes},
47 * {@link android.R.styleable#Button Button Attributes},
48 * {@link android.R.styleable#TextView TextView Attributes},
49 * {@link android.R.styleable#View View Attributes}
50 * </p>
51 */
52public class RadioButton extends CompoundButton {
53
54 public RadioButton(Context context) {
55 this(context, null);
56 }
57
58 public RadioButton(Context context, AttributeSet attrs) {
59 this(context, attrs, com.android.internal.R.attr.radioButtonStyle);
60 }
61
62 public RadioButton(Context context, AttributeSet attrs, int defStyle) {
63 super(context, attrs, defStyle);
64 }
65
66 /**
67 * {@inheritDoc}
68 * <p>
69 * If the radio button is already checked, this method will not toggle the radio button.
70 */
71 @Override
72 public void toggle() {
73 // we override to prevent toggle when the radio is already
74 // checked (as opposed to check boxes widgets)
75 if (!isChecked()) {
76 super.toggle();
77 }
78 }
Svetoslav Ganov76502592011-07-29 10:44:59 -070079
80 @Override
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -080081 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
82 super.onInitializeAccessibilityEvent(event);
83 event.setClassName(RadioButton.class.getName());
84 }
85
86 @Override
87 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
88 super.onInitializeAccessibilityNodeInfo(info);
89 info.setClassName(RadioButton.class.getName());
90 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091}