이 레이아웃을 호스팅하는 Activity 또는 Fragment 내에서 라디오 버튼을 찾아 다음과 같이 각 버튼에 변경 리스너를 설정합니다.
Kotlin
findViewById<RadioButton>(R.id.radio_pirates).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("RADIO","Pirates is checked: $isChecked")}findViewById<RadioButton>(R.id.radio_ninjas).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("RADIO","Ninjas is checked: $isChecked")}
자바
findViewById<RadioButton>(R.id.radio_pirates).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("RADIO","Pirates is checked: $isChecked");}findViewById<RadioButton>(R.id.radio_ninjas).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("RADIO","Ninjas is checked: $isChecked");}
이 예에서는 사용자가 라디오 버튼 중 하나를 탭하면 Logcat에 메시지가 출력됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Add radio buttons to your app\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to add components in Compose. \n[Radio buttons →](/develop/ui/compose/components/radio-button) \n\nRadio buttons let the user select one option from a set of mutually exclusive\noptions. Use radio buttons if the user needs to see all available options\nlisted. If it's not necessary to show all options, use a\n[spinner](/guide/topics/ui/controls/spinner) instead.\n| **Note:** For a better user experience, see the Material Design [Radio\n| button](https://m3.material.io/components/radio-button/overview) documentation.\n**Figure 1.** An example of radio buttons from [Material\nDesign](https://m3.material.io/components/radio-button/overview).\n\nTo create each radio button option, create a\n[RadioButton](/reference/android/widget/RadioButton)\nin your layout. Because radio buttons are mutually exclusive, group them inside\na\n[RadioGroup](/reference/android/widget/RadioGroup).\nThe system ensures that only one radio button within a group can be selected at\na time.\n\nRespond to click events\n-----------------------\n\nWhen the user selects a radio button, the corresponding\n`RadioButton` object receives an on-click event.\n\nThe following example shows a reaction to the user tapping a\n`RadioButton` object in a group: \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cRadioGroup\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:orientation=\"vertical\"\u003e\n \u003cRadioButton android:id=\"@+id/radio_pirates\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"Pirates\"/\u003e\n \u003cRadioButton android:id=\"@+id/radio_ninjas\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"Ninjas\"/\u003e\n\u003c/RadioGroup\u003e\n```\n| **Note:** `RadioGroup` is a subclass of [LinearLayout](/reference/android/widget/LinearLayout) that has a vertical orientation by default.\n\nWithin the `Activity` or `Fragment` that hosts this\nlayout, find your radio buttons and set a change listener for each of them, as\nfollows: \n\n### Kotlin\n\n```kotlin\nfindViewById\u003cRadioButton\u003e(R.id.radio_pirates).setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"RADIO\", \"Pirates is checked: $isChecked\")\n}\n\nfindViewById\u003cRadioButton\u003e(R.id.radio_ninjas).setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"RADIO\", \"Ninjas is checked: $isChecked\")\n}\n```\n\n### Java\n\n```java\nfindViewById\u003cRadioButton\u003e(R.id.radio_pirates).setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"RADIO\", \"Pirates is checked: $isChecked\");\n}\n\nfindViewById\u003cRadioButton\u003e(R.id.radio_ninjas).setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"RADIO\", \"Ninjas is checked: $isChecked\");\n}\n```\n\nIn this example, when the user taps one of the radio buttons, a message\nprints in Logcat.\n| **Tip:** If you need to change the radio button state yourself, use the [setChecked(boolean)](/reference/android/widget/CompoundButton#setChecked(boolean)) or [toggle()](/reference/android/widget/CompoundButton#toggle()) method."]]