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 children views are not ready yet. Using a tree observer on the RecyclerView
seems to solve the problem, but what would be the best approach to get the last visible item after setting content to the adapter right after creation?
recyclervew.setLayoutManager(layoutManager)
– Prosopopoeia