Вы можете использовать этот способ. Во-первых, все флажки должны быть в одном макете. И затем вы используете этот блок кода.
макет. xml
...
<CheckBox android:id="@+id/allCheckbox" />
<LinearLayout android:id="@+id/checkboxLayouts"...>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
...
Код
LinearLayout checkboxLayout = findViewById(R.id.checkboxLayouts);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
for(int i=0 ; i < checkboxLayout.getChildCount(); i++) {
if(checkboxLayout.getChildAt(i) instanceof CheckBox) {
((CheckBox) checkboxLayout.getChildAt(i)).setChecked(isChecked);
}
}
}
});
Примечание: я не могу проверить код. Извините за синтаксическую ошибку.