Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Fixed a crash when the adapter still triggers the update of the previous recycler view #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KelvinJin
Copy link

How to reproduce the bug:

  • Assign a non-null adapter adapter to a SuperRecyclerView instance recyclerView: recyclerView.setAdapter(adapter)
  • Assign a null adapter to the recyclerView: recyclerView.setAdapter(null).
  • Call adapter.notifyDataSetChanged().

The recyclerView will get notified since the observer is not cancelled. But now, recyclerView.getAdapter() will return null, this will crash when recyclerView.getAdapter().getCount() is called.

This PR fixed this issue by cancelling the observation once the adapter is changed. (Essentially this is how the official RecyclerView handles adapter changing.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant