728x90
public class MainActivity extends AppCompatActivity {
int nChecked = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Switch switchButton = findViewById(R.id.sw_opt);
switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked) {
// switchButton์ด ์ฒดํฌ๋ ๊ฒฝ์ฐ
nChecked = 1;
} else {
// switchButton์ด ์ฒดํฌ๋์ง ์์ ๊ฒฝ์ฐ
nChecked = 0;
}
}
});
}
...
๋๊ธ