Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- AWS
- 암호학
- Coroutines
- Rxjava
- activity
- MiTweet
- architecture
- 프로그래머스
- 코루틴
- GitHub
- pandas
- MyVoca
- 백준
- 쿠링
- ProGuard
- TEST
- textfield
- Compose
- relay
- android
- livedata
- boj
- Codeforces
- 코드포스
- Python
- Gradle
- androidStudio
- Kotlin
- Hilt
- Coroutine
Archives
- Today
- Total
이동식 저장소
[Android] Transformations.map이 동작하지 않을 때 본문
문제 상황
Transformations.map(liveData)
를 이용하여 새로운 LiveData
를 선언하였지만, 제대로 변환되지 않는 문제가 있다.
문제 원인
반환된 LiveData
를 observe하는 뷰가 없기 때문이다. Transformations
는 반환된 LiveData
가 observe될 때에만 변환을 수행한다.
해결 방법
Fragment 등에서 해당 LiveData
를 observe하면 된다. 가장 단순한 방법으로는 listener를 비워 놓으면 된다.
// QuizFragment.onCreateView()에서
quizViewModel.quizAvailable.observe(viewLifecycleOwner) { }
고작 이거 하나 때문에 일주일 동안 고민했다는 게.. 참.. 인생무상이다.
'Primary > Android' 카테고리의 다른 글
[Hilt] 1. 의존성 주입이란? (1) | 2021.04.29 |
---|---|
[Android] Cannot invoke setValue on a background thread (0) | 2021.03.14 |
[Android Kotlin Fundamentals] Lifecycle (2) | 2021.02.03 |
[Android Kotlin Fundamentals] Navigation path (0) | 2021.02.02 |
Inflate()에서 매개변수 attachToParent의 의미 (2) | 2020.12.22 |