Get the last visible RecyclerView element

findLastVisibleItemPosition returns -1 with the following sequence:

 onViewCreated() { recyclerView.setAdapter(adapter = new Adapter()); adapter.updateContent(List<Content>); // will call notifyItemRangeChanged post(new Runnable() { run() { layoutManager.getLastVisibleItem(); // == -1 (using runnable or not) } } } 

It seems that the views of the children are not yet ready. Using a tree viewer in RecyclerView seems to solve the problem, but what is the best approach to get the last visible item after setting the adapter contents right after creation?

+1
android android-recyclerview android-adapter
Aug 25 '15 at 0:15
source share

No one has answered this question yet.

See similar questions:

52
The toolbar in AppBarLayout scrolls, although the RecyclerView is not enough to scroll

or similar:

1770
Get screen sizes in pixels
877
Why doesn't RecyclerView have onItemClickListener ()?
868
How to add separators and spaces between elements in RecyclerView?
782
How to create a RecyclerView with multiple view types?
511
RecyclerView onClick
231
Getting visible items in a RecyclerView
56
Add software product for recyclerview?
10
RecyclerView: find the last visible item immediately after creating the view
2
How to add an addition to the last view in RecyclerView only if RecyclerView scrolls?
0
scrollToPosition only correctly scrolls visible elements in RecyclerView



All Articles