챕터1부분 질문입니다.
428
작성한 질문수 192
왼쪽이 제가 작성한 부분이고 오른쪽이 선생님강의입니다.
코인 선택화면 API 데이터 받아와서 확인 (Retrofit / Coroutine) 7분에서
1. 제가 작성한 부분이 ViewModel 은 lifecycle이고 선생님께서 작성하신viewModel은 selectViewModel로 되어있는데요.
이거 뭔차이가있나요?
SelectViewModel 클래스를 ViewModel()타입으로 선언한거를 SelectActivity.kt에 ViewModel 변수에 넣어준거 맞나요?
2.코인 선택화면 API 데이터 받아와서 확인 (Retrofit / Coroutine) 10분에서
class NetworkRepository {
private val client=RetrofitInstance.getInstance().create(Api::class.java)
suspend fun getCurrentCoinList1()=client.getCurrentCoinList()//API주소
}
이런코드가있는데요.
getCurrentCoinList1()가 함수인거 같은데 대입연산자 사용이 가능한가요?
3 NetworkRepository에서요.
코드
.class NetworkRepository {
private val client=RetrofitInstance.getInstance().create(Api::class.java)
//클래스RetrofitInstance 에서 retrofit형식을 가진 client를 불러온다.
suspend fun getCurrentCoinList1()=client.getCurrentCoinList()//API주소
}
이런코드가있는데요.
suspend fun getCurrentCoinList1()=client.getCurrentCoinList()//API주소
질문3번 :getCurrentCoinList()함수가 api클래스 내부 함수인거 같은데요.
근데 RetrofitInstance.getInstance()여기서는 api파일을 받은게 없는데 어떻게 api 함수인 getCurrentCoinList()를 쓸수있나요?
}
4. 데이터 코인 선택 Acitivity로 받아오기 (LiveData) 1분22초에서

원래코드는 이건데요.
class SelectViewModel : ViewModel() {
private val netWorkRepository = NetWorkRepository()
private lateinit var currentPriceResultList : ArrayList<CurrentPriceResult>
// 데이터변화를 관찰 LiveData
private val _currentPriceResult = MutableLiveData<List<CurrentPriceResult>>()
val currentPriceResult : LiveData<List<CurrentPriceResult>>
get() = _currentPriceResult
fun getCurrentCoinList() = viewModelScope.launch {
val result = netWorkRepository.getCurrentCoinList()
currentPriceResultList = ArrayList()
for(coin in result.data) {
================================================
class SelectViewModel : ViewModel() {
private val netWorkRepository = NetWorkRepository()
private lateinit var currentPriceResultList : ArrayList<CurrentPriceResult>
fun getCurrentCoinList() = viewModelScope.launch {
// 데이터변화를 관찰 LiveData
private val _currentPriceResult = MutableLiveData<List<CurrentPriceResult>>()
val currentPriceResult : LiveData<List<CurrentPriceResult>>
get() = _currentPriceResult
val result = netWorkRepository.getCurrentCoinList()
currentPriceResultList = ArrayList()
for(coin in result.data) {
이렇게 작성하면 LiveData를 viewModelScope.launch {안에 넣어주면 위사진처럼 get()을 import하면 뭔가 많이 나오는데 이건 왜이런건가요?
답변 1
0
잘 이해하신 것 같은데 ViewModel -> viewModel 로 대소문자 변경해보시겠어요?
아래 이미지처럼 궁금하시면 직접 해보시면 됩니다

4. 전체 코드와 스크린샷을 공유해주시면 좀 더 답변드리기 좋을 것 같습니다~
빌드가 안 돼요..
0
78
2
압축 폴더 파일이 비어있어요ㅠ
0
1203
2
bottom navigation view 색깔
0
112
1
[룸DB 관련 에러] can't open offline database '/data/data/ ...
0
293
3
강의명: 코인 선택화면 Adapater 세팅 (RecyclerView) 에서
0
194
3
6:50분 즈음부터 recycler view 재활용 관련 말이 나오는데
0
170
1
섹션 4 다 완성하고 실행시켜보니 NumberFormatEx이 뜨네요
0
293
2
Notification을 실행했을때
0
824
1
Database Inspector에서 db가 closed 일때
0
430
1
Fragment 에서 다른 Activity로는 Navigation을 사용하지 않나요??
0
256
1
notification 문의드립니다.
0
222
1
풀 소스 코드는 없나요!?
0
319
2
안드로이드버전에 따라 다른것이있을까요?
0
356
2
HTML 코드
0
238
1
BroadcastReceiver가 안됩니다ㅠㅠ
0
510
1
15, 30, 45분 데이터 및 어댑터 오류
0
286
1
_ 사용하시는 이유가 있으실까요?
0
232
1
15, 30, 45 분 데이터가 쌓이지 않습니다.
0
339
1
SQL문 쓰실 때 글자 색깔이 다른데 어떤걸 사용하시는지 알 수 있을까요?
0
221
1
안드로이드13 알림 권한
0
580
1
인트로 화면 세팅에서 질문있습니다.
0
279
1
datastore 관련 질문있습니다.
0
385
1
typeconverter 오류 문의드립니다.
0
392
2
navigation 관련 질문 있습니다
0
330
2





