I've implemented a tracker to my recyclerView, and it works fine. my problem is when I add some items to my recycler or even renew the whole adapter, the tracker won't work.
the crash is out of range for returning key from dataArray which is passed to ChatItemKeyProvider in the creation of SelectionTracker
the code for getKey is this:
@Nullable
override fun getKey(i: Int): String {
return mPokemonList[i]!!._id
}
what I've tried so far:
everyTime I add some data to my adapter,I set the tracker in adapter to null and renew my tracker again, but still its crashing. the example code is like this :
tracker = null
chatAdapter.setTracker(null)
tracker = SelectionTracker.Builder(
chatId,
chatRecycler,
ChatItemKeyProvider(newResult, myUserId),
ChatItemDetailsLookup(chatRecycler),
StorageStrategy.createStringStorage()
).withSelectionPredicate(
SelectionPredicates.createSelectAnything()
).build()
chatAdapter.setTracker(tracker)
my question is how to update my tracker when data is updated?