CheckBox 속성, 메소드 정리
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.widget.TextView | ||||
↳ | android.widget.Button | ||||
↳ | android.widget.CompoundButton | ||||
↳ | android.widget.CheckBox |
1. android:text [ setText(CharSequence) ] : 체크박스 텍스트
2. isChecked() : 체크박스 체크 여부(CompoundButton클래스의 메소드)
3. setChecked(boolean checked) : 체크 설정.
4. toggle() : Change the checked state of the view to the inverse of its current state . 체크상태를 토글
5. 사용예제
(1)
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
if (checkBox.isChecked()) {
checkBox.setChecked(false);
}
}
}
(2)
final CheckBox check_button = (CheckBox) findViewById(R.id.checkbox);
check_button.setOnClickListener(new View.OnClickListener() {
public void onClick (View v) {
TextView tv = (TextView)findViewById(R.id.checkbox);
tv.setText(check_button.isChecked() ? "This option is checked": "This option is not checked");
}
});
CheckBox 진짜 헤맸다 ㅜㅜ 동동님 감사합니다
[출처] CheckBox 속성, 메소드 정리|작성자 동동