code: public void setAdapter(Adapter adapter) {
          if (mAdapter != null) {
              mAdapter.unregisterAdapterDataObserver(mObserver);
          }
          // end all running animations
          if (mItemAnimator != null) {
              mItemAnimator.endAnimations();
          }
          // Since animations are ended, mLayout.children should be equal to recyclerView.children.
          // This may not be true if item animator's end does not work as expected. (e.g. not release
          // children instantly). It is safer to use mLayout's child count.
          if (mLayout != null) {
              mLayout.removeAndRecycleAllViews(mRecycler);
              mLayout.removeAndRecycleScrapInt(mRecycler, true);
          }
  
          final Adapter oldAdapter = mAdapter;
          mAdapter = adapter;
          if (adapter != null) {
              adapter.registerAdapterDataObserver(mObserver);
          }
          if (mLayout != null) {
              mLayout.onAdapterChanged(oldAdapter, mAdapter);
          }
          mRecycler.onAdapterChanged(oldAdapter, mAdapter);
          mState.mStructureChanged = true;
          markKnownViewsInvalid();
          requestLayout();
      }
docs: Set a new adapter to provide child views on demand.
  
  @param adapter The new adapter to set, or null to set no adapter.