专注高级工程师进阶,共同成长,共度寒冬
如果使用过 android architecture 中关于 LiveData 部分的朋友,可能对于DiffUtils
这个玩意儿并不陌生。
在使用 DiffUtils 之前,如果想使用Adapter
的notify
系列函数,可能并不是那么方便,我们想象下,需要知道一个列表对于另外一个列表的difference
,我们想简单的实现一个这种方法,并不是可以一下子写出来的。好在我们发现 Google 提供了这个工具类,就是DiffUtils
。
DiffUtils.java 头部相关的介绍
1/*2 * android.support.v7.util.DiffUtils3 *4 * DiffUtil uses Eugene W. Myers's difference algorithm to calculate the minimal number of updates5 * to convert one list into another. Myers's algorithm does not handle items that are moved so6 * DiffUtil runs a second pass on the result to detect items that were moved.7 *//*
2 * android.support.v7.util.DiffUtils
3 *
4 * DiffUtil uses Eugene W. Myers's difference algorithm to calculate the minimal number of updates