8

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
}
Ruan_Lopes
  • 1,381
  • 13
  • 18
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135

2 Answers2

12

simply you can do this:

    if(position == myList.size()-1){/*lastItem*/}
Kosh
  • 6,140
  • 3
  • 36
  • 67
9

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
       }
}
Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103