Here is how you add a switch to your layout.
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/someSwitchIdentifier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/some_string_value" />
Here is how you set the switch state using code.
binding.someSwitchIdentifier.isChecked = true // or false
Here is how you observe state change of a switch.
binding.someSwitchIdentifier.setOnCheckedChangeListener{ switch, isChecked ->
Log.d("Switch", "Do something here")
}