CheckedBox
<CheckBox
android:id="@+id/checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="CheckBox" />
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_buttons)
val checkBox = findViewById<CheckBox>(R.id.checkbox)
checkBox.isChecked = false
val isChecked = checkBox.isChecked
checkBox.setOnCheckedChangeListener {
buttonView, isChecked ->
Log.e(
"Tag",
"onCheckedChanged$isChecked"
)
}
}
RadioButton
- Radio control
- Can be used with RadioGroup, only one can be selected
- Difference from CheckedBox:
- Can't become unselected by clicking
- A group of RadioButton, only one can be selected
- It is displayed in a circle by default in most UI frameworks
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioButtion1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton"/>
<RadioButton
android:id="@+id/radioButtion2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton"/>
<RadioButton
android:id="@+id/radioButtion3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton"/>
</RadioGroup>
ToggleButton
- Switch status in the program
- Two states:
- android: textOn = “hello”
- android: textOff = "byebye"
- setChecked(boolean)
- setOnCheckedChangeListener
<ToggleButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toggleButton"
android:textOn="hello"
android:textOff="byebye"
android:checked="true"
android:text="ToggleButton"/>