如果我以不同的项目顺序提交相同的列表,ListAdapter不会刷新RecyclerView [英] ListAdapter not refreshing RecyclerView if I submit the same list with different item order

查看:121
本文介绍了如果我以不同的项目顺序提交相同的列表,ListAdapter不会刷新RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将RecyclerView ListAdapter一起使用(使用 AsyncListDiffer 进行计算)并在替换列表时更改动画).

I am using a RecyclerView with ListAdapter (which uses AsyncListDiffer to calculate and animate changes when list is replaced).

问题是,如果我submit()一些列表,然后重新排序该列表,然后再次submit(),则什么也没有发生.

The problem is that if I submit() some list, then re-order that list, and submit() again, nothing happens.

我如何强制ListAdapter评估这个新列表,即使它相同"(但顺序已更改)?

How do I force ListAdapter to evaluate this new list, even though it is "the same" (but order has changed)?

新发现:

我检查了

I checked source code of submitList() and in the beggining there is a check:

public void submitList(@Nullable final List<T> newList) {
        final int runGeneration = ++this.mMaxScheduledGeneration;
        if (newList != this.mList) {

我认为这是问题所在.但是如何克服呢?我的意思是,开发人员肯定会考虑提交其他有序列表吗?

I think this is the problem. But how to get past it? I mean, surely the developers thought about submiting a different ordered list?

推荐答案

该函数将不会被调用,因为ListAdapter不会将其视为另一个列表,因为它具有所有相同的项目只有订单被更改了.

That function will not get called because ListAdapter won't consider it as another list, since it has all the same items only the order got changed.

@Override
public void submitList(@Nullable final List<T> list) {
super.submitList(list != null ? new ArrayList<>(list) : null);
}

因此,要解决此问题,您需要先使用null调用此函数,然后立即使用顺序已更改的列表进行调用.

So to solve this, you need to call this function with null first, then immediately call with the order changed list.

submitList(null);
submitList(orderChangedList);

这篇关于如果我以不同的项目顺序提交相同的列表,ListAdapter不会刷新RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆