Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- activity
- Compose
- TEST
- intent
- 테스트
- Coroutines
- LifeCycle
- CustomScrollView
- binding
- livedata
- Button
- Dialog
- Navigation
- viewmodel
- 안드로이드
- 계측
- android
- textfield
- scroll
- 앱
- DART
- appbar
- data
- Kotlin
- Flutter
- 앱바
- ScrollView
- tabbar
- drift
- textview
Archives
- Today
- Total
Study Record
[안드로이드] RadioButton, RadioGroup 살펴보기 본문
728x90
😶 RadioGroup 과 RadioButton
RadioButton 은 여러개의 옵션을 선택할 때 사용한다. RadioGroup 내부의 RadioButton 을 여러개 배치해서 RadioButton 들 중 하나의 RadioButton 만을 선택할 수 있다.
<RadioGroup
android:id="@+id/radio_group"
android:checkedButton="@+id/radio_one"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radio_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:text="아주 만족"/>
<RadioButton
android:id="@+id/radio_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:text="보통"/>
<RadioButton
android:id="@+id/radio_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:text="불만족"/>
</RadioGroup>
<RadioButton> 의 android:checked 속성을 true 로 하거나 <RadioGroup> 의 android:checkedButton 속성의 id 값을 입력하면 라디오 그룹 내에서 해당 라디오가 선택된다.
라디오 이벤트
라디오 버튼이 클릭될 때마다 setOnCheckedChangeListener 이벤트로 클릭된 라디오 id 값(checkId)을 받을 수 있다.
binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
when(checkedId) {
binding.radioOne.id -> {
}
binding.radioTwo.id -> {
}
binding.radioThree.id -> {
}
}
}
선택된 라디오 해제하기
선택된 라디오가 없는, 즉 선택하기 전의 상태로 돌아가고 싶다면 RadioGroup 의 clearCheck() 함수를 사용한다.
binding.radioGroup.clearCheck()
라디오 버튼 | Android 개발자 | Android Developers
라디오 버튼 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 라디오 버튼을 사용하면 세트에서 한 가지 옵션을 선택할 수 있습니다. 사용 가능한 모든 옵션
developer.android.com
728x90
'안드로이드' 카테고리의 다른 글
[안드로이드] 간단한 계측 테스트 실행해보기 (0) | 2023.07.15 |
---|---|
[안드로이드] 아이콘, 적응형 앱 아이콘 (0) | 2023.07.12 |
[안드로이드] 문자열 따로 저장하고 불러오기(strings.xml) (0) | 2023.07.03 |
[안드로이드] 디버깅 살펴보기 (0) | 2023.07.03 |
[안드로이드] 자동화 테스트 기본 사항 (0) | 2023.06.30 |