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 |
Tags
- Navigation
- DataBinding
- activity
- Coroutine
- AppBarLayout
- LiveData
- ViewModel
- Algorithm
- 코틀린
- 안드로이드
- HTTP
- Behavior
- View
- onMeasure
- 알고리즘
- sqlite
- notification
- BOJ
- hilt
- CollapsingToolbarLayout
- lifecycle
- 알림
- 백준
- CustomView
- kotlin
- CoordinatorLayout
- onLayout
- Android
- room
- recyclerview
Archives
- Today
- Total
개발일지
Android in A..Z - Paging3 (Pager) 본문
Pager
PagingConfig를 바탕으로 PagerSource로부터 PagingData를 만들어서 Flow형으로 반환한다.
코드
@HiltViewModel
class ViewerViewModel @Inject constructor(): ViewModel() {
fun getPagingData(webToon: WebToon, episode: Int): Flow<PagingData<String>> {
return Pager(PagingConfig(pageSize = 10), episode - 1) {
ViewerPagingSource(webToon, episode)
}.flow
// 데이터를 변환해야 할 경우
// .map {
// it
// }
.cachedIn(viewModelScope)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycleScope.launchWhenResumed {
viewModel.getPagingData(webToon, episode).collect {
viewerPagingAdapter.submitData(it)
}
}
}
Pager
PagingConfig를 바탕으로 PagerSource를 통해 PagingData를 만들고 Flow형으로 반환한다.
매개변수로 PagingConfit, initialKey, PagingSourceFactory, RemoteMediator를 받는다.
PagingConfig
Pager의 구성요소로 Paging 기법에 관련된 설정을 제공합니다.
Git (예제코드)
https://github.com/KangTaeJong98/Example/tree/main/Android/Paging
KangTaeJong98/Example
My Example Code. Contribute to KangTaeJong98/Example development by creating an account on GitHub.
github.com
'Android (안드로이드) > Paging' 카테고리의 다른 글
Android in A..Z - Paging (PagingAdapter) (0) | 2021.05.25 |
---|---|
Android in A..Z - Paging3 (PagingSource) (0) | 2021.05.25 |
Android in A..Z - Paging3 (개념) (0) | 2021.05.25 |
Comments