Reputation: 4487
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
}
Upvotes: 8
Views: 16578
Reputation: 22537
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
}
}
Upvotes: 9
Reputation: 6334
simply you can do this:
if(position == myList.size()-1){/*lastItem*/}
Upvotes: 12