RecyclerView refreshes items only when scrolling down and up

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 03:27:59

This is happening because position 0 is above the current visible screen. Until transcript mode is implemented, when you are adding an item to position N, try calling scrollToPosition(N) if LinearLayoutManager#findFirstCompletelyVisibleItemPosition returns N.

Also, don't make the position parameter final in your onBindViewHolder method. Instead, use ViewHolder.getPosition() if you need it in a callback. When position of the item changes, you will not receive an onBind call unless the item itself is invalidated.

Update

Also your update logic is not correct because you are not clearing values in views.

if (!movie.getTagline().isEmpty()) {
    movieViewHolder.tagline.setText(movie.getTagline());
} else if (!movie.getPlot().isEmpty()) {
    movieViewHolder.tagline.setText(movie.getPlot());
} else {
    movieViewHolder.tagline.setText(null);
}

Same for the poster URL.

layoutManager.scrollToPosition didn't solve the problem for me.

Not a definitive solution, but the following line did the trick in my case:

recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, null, 0);

Hope it helps...

Adding this solved the problem to me

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