How to know last item in RecyclerView
14,379
Solution 1
simply you can do this:
if(position == myList.size()-1){/*lastItem*/}
Solution 2
You can use getItemCount() or the size of your adapter list.
@Override
public void onBindViewHolder(UserViewHolder userViewHolder, int position) {
if( position == getItemCount() - 1 ){
// Your last item
}
}
Author by
JayVDiyk
Updated on July 29, 2022Comments
-
JayVDiyk almost 2 years
In my
RecyclerViewAdapter
, I would like to know if this item is the last. How can I check it?The
onBindViewHolder
only has the position value@Override public void onBindViewHolder(UserViewHolder userViewHolder, int position) { //DO SOMETHING TO THE VIEW IF THIS IS THE LAST ITEM IN RECYCLERVIEW }