Created
February 7, 2022 10:59
-
-
Save sumeetph/7a7a00813e590bb5da2b76f809ceeca3 to your computer and use it in GitHub Desktop.
CacheOnViewDeatched
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Saving the cached item once it goes out of screen | |
| override fun onViewDetachedFromWindow(holder: ViewHolder) { | |
| if (cachedViewHolderTypes.contains(holder.itemViewType)) { | |
| val pos = holder.bindingAdapterPosition | |
| Timber.d("onViewDetached called for position : $pos") | |
| if (pos > -1) { | |
| holder.setIsRecyclable(false) | |
| cachedItems[getCachedItemId(pos)] = holder | |
| } | |
| } | |
| super.onViewDetachedFromWindow(holder) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment