1)Activity_Main.xml
2)MainActivity.java
package kr.android.s07checkboxdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
CheckBox cb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cb=(CheckBox)findViewById(R.id.checkBox);
//이벤트 연결
cb.setOnCheckedChangeListener(this);
}
//이벤트 핸들러
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
cb.setText("체크 상태");
}else{
cb.setText("체크되지 않은 상태");
}
}
반응형
'IT > Android Studio' 카테고리의 다른 글
Android Studio s11LinearLayoutDemo03 (0) | 2020.07.01 |
---|---|
Android Studio s08RadioButtonDemo (0) | 2020.07.01 |
Android Studio s06EditTextDemo (0) | 2020.07.01 |
Android Studio s05ImageViewDemo (0) | 2020.06.30 |
Android Studio 코드 입력시 자동으로 import (0) | 2020.06.30 |