<Switch android:id="@+id/switchWrite" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:text="NDEF Message write" android:textOff="NDEF Message write Off" android:textOn="NDEF Message write On" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/writeButton" app:layout_constraintHorizontal_bias="0.076" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/ndefWrite" app:layout_constraintVertical_bias="0.087" />
final Switch switchWrite = (Switch) findViewById(R.id.switchWrite); switchWrite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked) { status.setText(switchWrite.getTextOn().toString()); } else { status.setText(switchWrite.getTextOff().toString()); } } });
if(switchWrite.isChecked()){ }