• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package android.widget;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 
22 
23 /**
24  * <p>
25  * A radio button is a two-states button that can be either checked or
26  * unchecked. When the radio button is unchecked, the user can press or click it
27  * to check it. However, contrary to a {@link android.widget.CheckBox}, a radio
28  * button cannot be unchecked by the user once checked.
29  * </p>
30  *
31  * <p>
32  * Radio buttons are normally used together in a
33  * {@link android.widget.RadioGroup}. When several radio buttons live inside
34  * a radio group, checking one radio button unchecks all the others.</p>
35  * </p>
36  *
37  * <p>See the <a href="{@docRoot}resources/tutorials/views/hello-formstuff.html">Form Stuff
38  * tutorial</a>.</p>
39  *
40  * <p><strong>XML attributes</strong></p>
41  * <p>
42  * See {@link android.R.styleable#CompoundButton CompoundButton Attributes},
43  * {@link android.R.styleable#Button Button Attributes},
44  * {@link android.R.styleable#TextView TextView Attributes},
45  * {@link android.R.styleable#View View Attributes}
46  * </p>
47  */
48 public class RadioButton extends CompoundButton {
49 
RadioButton(Context context)50     public RadioButton(Context context) {
51         this(context, null);
52     }
53 
RadioButton(Context context, AttributeSet attrs)54     public RadioButton(Context context, AttributeSet attrs) {
55         this(context, attrs, com.android.internal.R.attr.radioButtonStyle);
56     }
57 
RadioButton(Context context, AttributeSet attrs, int defStyle)58     public RadioButton(Context context, AttributeSet attrs, int defStyle) {
59         super(context, attrs, defStyle);
60     }
61 
62     /**
63      * {@inheritDoc}
64      * <p>
65      * If the radio button is already checked, this method will not toggle the radio button.
66      */
67     @Override
toggle()68     public void toggle() {
69         // we override to prevent toggle when the radio is already
70         // checked (as opposed to check boxes widgets)
71         if (!isChecked()) {
72             super.toggle();
73         }
74     }
75 }
76