체크박스는 <CheckBox>를 사용한다.
On/Off 상태를 구할 땐 setOnCheckedChangeListener를 사용한다.
1 2 3 4 | <CheckBox android:id="@+id/checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" /> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Toast.makeText(MainActivity.this, "체크상태 : " + isChecked, Toast.LENGTH_SHORT).show(); } }); } | cs |
'Android' 카테고리의 다른 글
[Android] SeekBar 사용 (0) | 2019.03.12 |
---|---|
[Android] 라디오 버튼(RadioButton) 사용 (0) | 2019.03.11 |
[Android] ToggleButton/Switch 사용 (0) | 2019.03.07 |
[Android] Button 상태에 따라 이미지 변경하기 (0) | 2019.03.06 |
[Android] Button 추가하기 (0) | 2019.03.05 |