diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index d2c71b2afe..f420ec2f08 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -499,8 +499,10 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo private void replaceRVContainer(boolean showTabs) { for (int i = 0; i < mAH.length; i++) { - if (mAH[i].recyclerView != null) { - mAH[i].recyclerView.setLayoutManager(null); + AllAppsRecyclerView rv = mAH[i].recyclerView; + if (rv != null) { + rv.setLayoutManager(null); + rv.setAdapter(null); } } View oldView = getRecyclerViewContainer(); diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java index 2c84a3d4b9..bddbbd00b2 100644 --- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java +++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java @@ -63,6 +63,13 @@ public class AllAppsRecyclerView extends BaseRecyclerView { private final SparseIntArray mCachedScrollPositions = new SparseIntArray(); private final AllAppsFastScrollHelper mFastScrollHelper; + + private final AdapterDataObserver mObserver = new RecyclerView.AdapterDataObserver() { + public void onChanged() { + mCachedScrollPositions.clear(); + } + }; + // The empty-search result background private AllAppsBackgroundDrawable mEmptySearchBackground; private int mEmptySearchBackgroundTopOffset; @@ -247,12 +254,13 @@ public class AllAppsRecyclerView extends BaseRecyclerView { @Override public void setAdapter(Adapter adapter) { + if (getAdapter() != null) { + getAdapter().unregisterAdapterDataObserver(mObserver); + } super.setAdapter(adapter); - adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { - public void onChanged() { - mCachedScrollPositions.clear(); - } - }); + if (adapter != null) { + adapter.registerAdapterDataObserver(mObserver); + } } @Override