public void setViewPager(ViewPager viewPager) {
    this.viewPager = viewPager;
    viewPager.setOnPageChangeListener(this);
    setPageCount(viewPager.getAdapter().getCount());
    viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() {
      @Override
      public void onChanged() {
        setPageCount(PagingIndicator.this.viewPager.getAdapter().getCount());
      }
    });
    setCurrentPageImmediate();
  }
Custom pager indicator for use with a {@link ViewPager}.
java/com/google/android/apps/authenticator/howitworks/PagingIndicator.java