inflearn logo
강의

Course

Instructor

[Intermediate] Friendly Introduction to JETPACK <Part 1> (Android Kotlin)

Map / SwitchMap - 2

Map / SwitchMap - 2 강의 오류

386

choidaehwan92822002

15 asked

0

Map / SwitchMap - 2 강의의 1분 29초 쯤에

val mapLiveData = Transformations.map(liveCount) {
    it+it
}

란 코드가 있는데요 Transformations 를 못불러오고

스크린샷 2023-12-11 오후 1.53.25.png강의자료를 그대로 복붙했는데 이런식으로 빨간줄이 납니다.
import를 못해오는거 같습니다

switchMap도 마찬가지로 안됩니다. Transformations 를 임포트 못받아옵니다!

 

찾아보니 gradle에 이부분을 임포트 받고

implementation("androidx.lifecycle:lifecycle-livedata-core:2.3.1")

이런식으로 사용하니까 되더라고요. 이런식으로 하고 진행해도 되는거겠죠?

class MainViewModel : ViewModel() {

    private var _mutableCount = MutableLiveData(0)
    val liveCount : LiveData<Int>
        get() = _mutableCount

    val mapLiveData = liveCount.map {
        it+it
    }

    val switchMapLiveData = liveCount.switchMap {
        changeValue(it)
    }

    fun setLiveDataValue(count : Int) {
        _mutableCount.value = count
    }

    fun changeValue(count : Int) : MutableLiveData<Int> {
        val testLiveData = MutableLiveData(count*count)
        return testLiveData
    }
}

android kotlin jetpack

Answer 1

0

bokchi

넵 정확한 것은 전체 프로젝트 코드를 봐야 알 것 같지만

말씀하신 것 처럼 사용하셔도 좋습니다!

dataBinding 시 오류

0

66

2

Retrfit 에러

0

146

2

[Retrofit 간단한 예제 변경 + RecyclerView 추가] 에 databinding 추가해 보았습니다.

1

218

2

Navigation Data Transfer Safe Args 강의중에서

0

267

2

viewModel 초기화 관련 질문드려요

0

283

1

Fragment에서 ViewBinding과 DataBinding 초기화 차이가 궁금합니다.

0

282

1

최상단 변수 선언 관련하여 질문드려요

0

190

1

Retrofit + ViewModelScope + RecyclerView + Glide 강의중에서

0

321

2

Retrofit 간단한 예제 변경 강의중에서

0

302

2

LiveData 와 MutableLiveData 차이강의중에서

0

502

5

Activity/Fragment ViewModel 공유 10분35초경에 fragment 에 viewModel선언

0

221

1

안드로이드 테마 색상 오류

0

245

1

에러

0

351

1

ViewBinding 질문 있습니다.

2

386

2

fragment 이동시 data 초기화

0

391

1

CoroutineScope 질문

0

371

1

뷰모델 질문

0

308

1

바인딩 때 xml

0

289

1

코루틴과 workmanager 순서 정하기의 차이점

0

521

1

ViewModel 값

0

296

1

Retrofit 질문입니다.

0

491

1

Activity / Fragment 의 ViewMode 질문있습니다.

0

317

1

2강 질문이씁니다.

0

283

1

Json 형식 데이터 모델 설계 질문드립니다 :)

2

1518

1