Get RecyclerView last visible item

穿精又带淫゛_ 提交于 2019-12-11 08:49:17

问题


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?

来源:https://stackoverflow.com/questions/32193675/get-recyclerview-last-visible-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!