Cara Menggunakan Radio Button | Komponen Android Studio

 




activity_pesan.xml

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rbPutra"
android:checked="true"
android:text="Putra Remaja"></RadioButton>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rbRosalia"
android:text="Rosalia Indah"></RadioButton>
</RadioGroup>


PesanActivity.kt

var bus : Int = 0
rgBus.setOnCheckedChangeListener { group, checkedId ->
bus = when(checkedId){
R.id.rbPutra -> 1
R.id.rbRosalia -> 2
else -> 0
}
}




Posting Komentar

Post a Comment (0)

Lebih baru Lebih lama