android:radiobutton
radiobutton
소개
스니펫
특별히 설명할게 없다.
@Composable fun KindRadioGroup( mItems: List<String>, selected: String, setSelected: (selected: String) -> Unit, ) { Row( modifier = Modifier.fillMaxWidth().padding(8.dp), horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically ) { mItems.forEach { item -> Row( verticalAlignment = Alignment.CenterVertically, ) { RadioButton( selected = selected == item, onClick = { setSelected(item) }, enabled = true, ) Text(text = item, modifier = Modifier.padding(start = 8.dp), fontSize = 16.sp, fontFamily = ttoppokki, fontWeight = FontWeight.SemiBold) } } } }
호출하기
위의 스니펫은 아래와 같이 호출하면 된다.
val (selected, setSelected) = remember { mutableStateOf(convertBooleanToYeah(medicalHistory.hasTreatment)) } ElevatedCard(elevation = CardDefaults.cardElevation(defaultElevation = 6.dp), modifier = Modifier .fillMaxWidth() .padding(6.dp)) { Column( modifier = Modifier .fillMaxWidth() .padding(8.dp), horizontalAlignment = Alignment.Start ) { KindRadioGroup( mItems = kinds, selected, setSelected ) if (selected == "예") { medicalHistory = medicalHistory.copy(hasTreatment = true) medicalHistory = medicalHistory.copy(visitingRecord = contactTextField(labelValue = "통원횟수(진료포함)", inputValue = medicalHistory.visitingRecord, example = "예 : 총 3회, ", painterResource = painterResource(id = R.drawable.baseline_edit_note_24))) medicalHistory = medicalHistory.copy(hospitalizedRecord = contactTextField(labelValue = "입원일수", inputValue = medicalHistory.hospitalizedRecord, example = "예 : 일주일, 없음, ", painterResource = painterResource(id = R.drawable.baseline_edit_note_24))) }else { medicalHistory = medicalHistory.copy(hasTreatment = false) medicalHistory = medicalHistory.copy(plannedToTreatment = dropDownTextField( items = listOf("자연 치유가 가능 합니다.", "외상은 없으나 병원 진료를 고려 중 입니다.", "병원에 예약을 하였습니다."), inputString = medicalHistory.plannedToTreatment )) } } }
android/radiobutton.txt · 마지막으로 수정됨: 2024/10/26 13:34 저자 이거니맨
로그인