title: How to find currently visible fragments in a viewpager while showing multiple fragments at once
body: <p>I am building an App in which multiple fragments are shown at once using ViewPager and FragmentStatePagerAdapter. Below is what I am doing: </p>
  
  <p><img src="https://i.stack.imgur.com/aag3k.png" alt="ScreenShot of ViewPager"></p>
  
  <pre><code>public class PageViewActivity extends FragmentActivity {
      protected static final String TAG = "PageViewActivity";
      MyPageAdapter pageAdapter;
      private List&lt;Fragment&gt; fragments;
      private FragmentManager fragmentManager;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_page_view);
  
          fragments = getFragments();
  
          fragmentManager = getSupportFragmentManager();
  
          pageAdapter = new MyPageAdapter(fragmentManager, fragments);
  
          ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
          pager.setAdapter(pageAdapter);
          pager.setOnPageChangeListener(new OnPageChangeListener() {
  
              @Override
              public void onPageSelected(int position) {
                  Log.i(TAG, "Inside onPageSelected....................... "
                          + position);
                  ((MyFragment) pageAdapter.getChildAt(position)).updateView();
              }
  
              @Override
              public void onPageScrolled(int arg0, float arg1, int arg2) {
                  Log.i(TAG, "Inside onPageScrolled... " + arg0);
              }
  
              @Override
              public void onPageScrollStateChanged(int arg0) {
                  Log.i(TAG, "Inside onPageScrollStateChanged... " + arg0);
              }
          });
      }
  
      private List&lt;Fragment&gt; getFragments() {
          List&lt;Fragment&gt; fList = new ArrayList&lt;Fragment&gt;();
  
          fList.add(MyFragment.newInstance("Fragment 1"));
          fList.add(MyFragment.newInstance("Fragment 2"));
          fList.add(MyFragment.newInstance("Fragment 3"));
          fList.add(MyFragment.newInstance("Fragment 4"));
          fList.add(MyFragment.newInstance("Fragment 5"));
          fList.add(MyFragment.newInstance("Fragment 6"));
          fList.add(MyFragment.newInstance("Fragment 7"));
  
          return fList;
      }
  
      private class MyPageAdapter extends FragmentStatePagerAdapter {
          private List&lt;Fragment&gt; fragments;
  
          public MyPageAdapter(FragmentManager fm, List&lt;Fragment&gt; fragments) {
              super(fm);
              this.fragments = fragments;
          }
  
          public void setList(List&lt;Fragment&gt; fragments) {
              this.fragments = fragments;
              notifyDataSetChanged();
          }
  
          @Override
          public Fragment getItem(int position) {
              Log.i(TAG, "Inside getItem............");
              return this.fragments.get(position);
          }
  
          @Override
          public int getCount() {
              return this.fragments.size();
          }
  
          @Override
          public float getPageWidth(int position) {
              if (position == 0) {
                  return 0.4f;
              } else {
                  return 0.3f;
              }
          }
  
          public Fragment getChildAt(int position) {
              return this.fragments.get(position);
          }
  
          @Override
          public int getItemPosition(Object object) {
              Log.i(TAG, "getItemPosition..........");
              if (fragments.contains(object)) {
                  Log.i(TAG,
                          "fragmentList.contains(object)... " + object.toString());
                  return POSITION_UNCHANGED;
              }
              return POSITION_NONE;
          }
  
                      }
      }
  }
  </code></pre>
  
  <p>My Question is how to find <strong>which fragments are visible??</strong> (eg Fragment 1, 2 and 3 from screen shot)  </p>
  
  <p>I know abot <strong>pager.setOnPageChangeListener</strong> and <strong>Fragment.setUserVisibleHint(boolean isVisibleToUser)</strong> but of no use to me :-(</p>
  
  <p>Your help is very appreciated. Thanks!!!</p>