timusus / RecyclerView-FastScroll

A simple FastScroller for Android's RecyclerView
Other
1.39k stars 183 forks source link

crash when invoke swapAdapter #100

Closed chundk closed 5 years ago

chundk commented 5 years ago

Exception throws when swapAdapter get called.

IllegalStateException("Observer " + observer + " was not registered.") E

Well, the solution is overriding swapAdapter

and copy method of setAdapter, instead of calling super.swapAdapter

@Override
public void swapAdapter(@NonNull Adapter adapter, boolean removeAndRecycleExistingViews) {

      if (getAdapter() != null) {
          getAdapter().unregisterAdapterDataObserver(mScrollOffsetInvalidator);
      }

      if (adapter != null) {
          adapter.registerAdapterDataObserver(mScrollOffsetInvalidator);
      }

    super.swapAdapter(adapter, removeAndRecycleExistingViews);
}
timusus commented 5 years ago

I'm not sure what SwapAdapter is, or what circumstances lead to this crash. This seems off topic and related to whatever library SwapAdapter belongs to.