Should the index passed to notifyItemChanged consider placeholder items?

232 views Asked by At

PagingDataAdapter from Paging3 library internally manages two semantically different lists. adapter.snapshot() returns a ItemSnapshotList which includes placeholder elements. adapter.snapshot().items return a List which excludes placeholder items.

Now I had to update an element using it's id. Should find and pass the index based on ItemSnapshotList or List? Eg:

adapter.notifyItemChanged(
    adapter.snapshot().indexOfFirst { it!!.id == id } // is this correct ?
    adapter.snapshot().items.indexOfFirst { it.id == id } // or is this ?
    , PAYLOAD_STATUS to Status.Active  // payloads
)
1

There are 1 answers

2
pnkj On

I think it's impossible. Any change on your item,you need to destroy and rebuild the pagingList.

I think the best practice is change in your room, and the list observe the room.