Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know last item in RecyclerView

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
}
like image 779
JayVDiyk Avatar asked Jan 07 '16 08:01

JayVDiyk


People also ask

How to get last position of RecyclerView in android?

Once the recyclerview is idle, use the findLastVisibleItemPosition or findLastCompletelyVisibleItemPosition functions provided by the LinearLayoutManager or GridLayoutManager to get the last position.

What is LinearLayoutManager in RecyclerView?

RecyclerView provides these built-in layout managers: LinearLayoutManager shows items in a vertical or horizontal scrolling list. GridLayoutManager shows items in a grid. StaggeredGridLayoutManager shows items in a staggered grid.

What does notifyDataSetChanged do in RecyclerView?

What does notifyDataSetChanged() do on recyclerview ? Notify any registered observers that the data set has changed. There are two different classes of data change events, item changes and structural changes. Item changes are when a single item has its data updated but no positional changes have occurred.

What is RecyclerView setHasFixedSize?

setHasFixedSize(true) means the RecyclerView has children (items) that has fixed width and height.


1 Answers

simply you can do this:

    if(position == myList.size()-1){/*lastItem*/}
like image 62
Kosh Avatar answered Sep 23 '22 06:09

Kosh