• CheckBox 클래스의 상속구조

• isChecked() – checkbox의 상태를 리턴.
• setChecked(true/false) – checkbox를 check/unckeck 함.
• toggle() – checkbox를 toggle.
• CheckBox를 사용했을 때 발생하는 event를 처리
• CompoundButton.OnCheckedChangeListener 상속
= onCheckedChanged(CompoundButton buttonview,
boolean isChecked)
체크여부에 따른 interface 구현 메소드
• setOnCheckedChangeListener()
= check 이벤트 발생했을 때 사용될 callback등록 하는 설정메소드


import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
// Activity를 상속 받아
// CompoundButton.OnCheckedChangedListener interface를 구현하는
// MyCheckBox Activity class
public class testSample extends Activity
implements CompoundButton.OnCheckedChangeListener {
CheckBox cb;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
cb = (CheckBox) findViewById(R.id.check);
cb.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cb.setText("This checkbox is: checked");
}
else {
cb.setText("This checkbox is: unchecked");
}
}
}
댓글 없음:
댓글 쓰기