code: public void setAdapter(PagerAdapter adapter) {
          if (mAdapter != null) {
              mAdapter.unregisterDataSetObserver(mObserver);
              mAdapter.startUpdate(this);
              for (int i = 0; i < mItems.size(); i++) {
                  final ItemInfo ii = mItems.get(i);
                  mAdapter.destroyItem(this, ii.position, ii.object);
              }
              mAdapter.finishUpdate(this);
              mItems.clear();
              removeNonDecorViews();
              mCurItem = 0;
              scrollTo(0, 0);
          }
  
          final PagerAdapter oldAdapter = mAdapter;
          mAdapter = adapter;
          mExpectedAdapterCount = 0;
  
          if (mAdapter != null) {
              if (mObserver == null) {
                  mObserver = new PagerObserver();
              }
              mAdapter.registerDataSetObserver(mObserver);
              mPopulatePending = false;
              final boolean wasFirstLayout = mFirstLayout;
              mFirstLayout = true;
              mExpectedAdapterCount = mAdapter.getCount();
              if (mRestoredCurItem >= 0) {
                  mAdapter.restoreState(mRestoredAdapterState, mRestoredClassLoader);
                  setCurrentItemInternal(mRestoredCurItem, false, true);
                  mRestoredCurItem = -1;
                  mRestoredAdapterState = null;
                  mRestoredClassLoader = null;
              } else if (!wasFirstLayout) {
                  populate();
              } else {
                  requestLayout();
              }
          }
  
          if (mAdapterChangeListener != null && oldAdapter != adapter) {
              mAdapterChangeListener.onAdapterChanged(oldAdapter, adapter);
          }
      }
docs: Set a PagerAdapter that will supply views for this pager as needed.
  
  @param adapter Adapter to use