2

We are using DiffUtil.CalculateDiff with a custom DiffUtil.Callback to handle changes to the underlying data.

  • The identity of our elements is rather complex, and that's why we are using custom equality check in areContentsTheSame and areItemsTheSame.

  • However, the adapter has two things hasStableIds and getItemId.

The problem is that getItemId returns a long and the identity of our elements can't be conflated into a long in a stable way (although otherwise stable considering our custom equality check in diffutil's callback.

The question is this:

What to do with hasStableIds and getItemId in this case, and are those at all used when DiffUtil is pushing changes to the adapter?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Kornelije Petak
  • 9,412
  • 15
  • 68
  • 96

1 Answers1

0

I don't know what has stables actually does in the background but it is used for keeping the elements in the order and remove any buggy stuff.

raj kavadia
  • 926
  • 1
  • 10
  • 30
  • Thanks for the reply, but unfortunatelly it doesn't help much. The point is: I know what hasStableIds does when using regular notifyDataSetChanged is used with adapter. But my question is specifically whether this is needed, or used at all when diffutil is used. – Kornelije Petak Mar 08 '19 at 09:04