CheckBox checkBox = findViewById(R.id.checkBox); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // Do something when CheckBox is checked } else { // Do something when CheckBox is unchecked } } });In this example, we set up a listener for a CheckBox that will be triggered when the CheckBox is checked or unchecked. You can place your code inside the appropriate block to do something when the CheckBox is checked or unchecked. Package Library: The android.widget CheckBox is part of the Android SDK and is located in the android.widget package.