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
- Plugins
- jsontokotlinclass
- shotcut
- Blinking
- onReceivedSslError
- onResume
- 이미지 gps
- BottomSheetDialog
- itemAnimator
- prettyJson
- kdoc-generator
- notification setting
- requestPermission
- datastore
- webview
- notification bar
- Git
- application
- notification
- LOG
- navigation component
- Android
- App Startup
- room
- ChromeCustomTab
- ActivityResultContracts
- skipcollapsed
- ExifInterface
- 403 Error
- circlecrop
Archives
- Today
- Total
Debbi Story
ViewPager2의 notifyDataSetChanged() 안될 때 본문
728x90
ViewPager2는 RecyclerView.Adapter 와 FragmentStateAdpater를 사용할 수 있습니다.
그중에 FragmentStateAdpater를 사용했을때 notifyDataSetChanged()를 해도 갱신이 안될 때
getItemId 와 containsItem 를 override 해주시면 됩니다!
아래는 예시 입니다.
class ViewPager2Adapter(fm: FragmentManager, private val fmList: ArrayList<Fragment>) : FragmentStateAdapter(fm) {
private val fmIds = fmList.map { it.hashCode().toLong() }
override fun getItemCount(): Int {
return fmList.size
}
override fun createFragment(position: Int): Fragment {
return fmList[position]
}
override fun getItemId(position: Int): Long {
return fmList[position].hashCode().toLong()
}
override fun containsItem(itemId: Long): Boolean {
return fmIds.contains(itemId)
}
}
'안드로이드 > Tip' 카테고리의 다른 글
Custom Notification bar 만들기 (0) | 2020.10.28 |
---|---|
Room Insert시 rowId 얻기 (0) | 2020.10.23 |
BottomSheetDialogFragment background 설정하기 (0) | 2020.09.10 |
DataBinding으로 layout_weight 값 적용하기 (0) | 2020.08.21 |
ViewPager2 가 Fragment 안에 있을때 (0) | 2020.08.18 |