레이아웃이 준비되면 Activity 또는 Fragment로 이동하여 CheckBox 뷰를 찾고 다음 예와 같이 변경 리스너를 설정합니다.
Kotlin
findViewById<CheckBox>(R.id.checkbox_meat).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("CHECKBOXES","Meat is checked: $isChecked")}findViewById<CheckBox>(R.id.checkbox_cheese).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("CHECKBOXES","Cheese is checked: $isChecked")}
자바
findViewById<CheckBox>(R.id.checkbox_meat).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("CHECKBOXES","Meat is checked: $isChecked");}findViewById<CheckBox>(R.id.checkbox_cheese).setOnCheckedChangeListener{buttonView,isChecked->
Log.d("CHECKBOXES","Cheese 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 checkboxes 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[Checkbox →](/develop/ui/compose/components/checkbox) \n| **Note:** For a better user experience, see the [Material Design Checkbox](https://m3.material.io/components/checkbox/overview) documentation.\n\nCheckboxes let the user select one or more options from a set. Typically, you present checkbox\noptions in a vertical list.\n**Figure 1.** An example of checkboxes from [Material Design Checkbox](https://m3.material.io/components/checkbox/guidelines).\n\nTo create each checkbox option, create a\n[CheckBox](/reference/android/widget/CheckBox) in your layout. Because\na set of checkbox options lets the user select multiple items, each checkbox is managed separately,\nand you must register a click listener for each one.\n\nRespond to click events\n-----------------------\n\nBegin by creating a layout with `CheckBox` objects in a list: \n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cLinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:orientation=\"vertical\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n \u003cCheckBox android:id=\"@+id/checkbox_meat\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"Meat\" /\u003e\n \u003cCheckBox android:id=\"@+id/checkbox_cheese\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"Cheese\"/\u003e\n\u003c/LinearLayout\u003e\n```\n\nOnce your layout is ready, head to your `Activity` or `Fragment`, find your\n`CheckBox` views, and set a change listener, as in the following example: \n\n### Kotlin\n\n```kotlin\nfindViewById\u003cCheckBox\u003e(R.id.checkbox_meat)\n .setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"CHECKBOXES\", \"Meat is checked: $isChecked\")\n }\n\nfindViewById\u003cCheckBox\u003e(R.id.checkbox_cheese)\n .setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"CHECKBOXES\", \"Cheese is checked: $isChecked\")\n }\n```\n\n### Java\n\n```java\nfindViewById\u003cCheckBox\u003e(R.id.checkbox_meat)\n .setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"CHECKBOXES\", \"Meat is checked: $isChecked\");\n }\n\nfindViewById\u003cCheckBox\u003e(R.id.checkbox_cheese)\n .setOnCheckedChangeListener { buttonView, isChecked -\u003e\n Log.d(\"CHECKBOXES\", \"Cheese is checked: $isChecked\");\n }\n```\n\nThe previous code prints a message in Logcat every time the checkboxes change status.\n| **Tip:** If you need to change the checkbox state yourself, use the [setChecked(boolean)](/reference/android/widget/CompoundButton#setChecked(boolean)) or [toggle()](/reference/android/widget/CompoundButton#toggle()) method."]]