There are several switches, which must be set same way:
private SwitchCompat switch1,switch2,...,switch10;
private void initSwitch(@NonNull SwitchCompat switchCompat) {
switchCompat.setOnCheckedChangeListener(this);
switchCompat.setTypeface(...);
}
How to pass switch id to initSwitch, so it would set all variables switch1, switch2, ..., switch10?
Because this will not work:
private void init(){
initSwitch(switch1, R.id.switch1)
initSwitch(switch1, R.id.switch2)
...
initSwitch(switch1, R.id.switch10)
}
private void initSwitch(@NonNull SwitchCompat switchCompat,int id) {
switchCompat.findById(id)
switchCompat.setOnCheckedChangeListener(this);
switchCompat.setTypeface(...);
}