Created
August 22, 2017 09:43
-
-
Save brownsoo/376f9fdaa7cb763982b6274cfe837736 to your computer and use it in GitHub Desktop.
Updates visible item views in RecyclerView
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
private void updateVisibleTaskIndex() { | |
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); | |
if (layoutManager instanceof LinearLayoutManager) { | |
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; | |
int first = linearLayoutManager.findFirstVisibleItemPosition(); | |
int last = linearLayoutManager.findLastVisibleItemPosition(); | |
RecyclerView.ViewHolder viewHolder; | |
for (int i = first; i <= last; i++) { | |
viewHolder = recyclerView.findViewHolderForAdapterPosition(i); | |
if (viewHolder instanceof TaskViewHolder) { //TaskViewHolder is custom holder | |
// Update view components in ViewHolder | |
((TaskViewHolder) viewHolder).updateIndex(i - taskSection.getIndex()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment