title: How to count fragments?
body: <p>I have an activity and pager adapter in it which displays 3 fragments. The fragments are shuffled. I need to know the number of each page when I am swiping through them and that number needs to be displayed in a textView. For example, when I am in the first page number 1 is displayed, second page - number 2 and so on.</p>
  
  <p><strong>PagerAdapter.java</strong></p>
  
  <pre><code>public class PagerAdapter extends FragmentPagerAdapter {
  
      private List&lt;Fragment&gt; fragments;
  
      public PagerAdapter(FragmentManager fm, List&lt;Fragment&gt; fragments) {
          super(fm);
          this.fragments = fragments;
      }
  
      @Override
      public Fragment getItem(int arg0) {
          return this.fragments.get(arg0);
      }
  
      @Override
      public int getCount() {
          return this.fragments.size();
      }
  
      public void setFragments(List&lt;Fragment&gt; fragments) {
          this.fragments = fragments;
      }
  }
  </code></pre>
  
  <p><strong>mainActivity.java</strong></p>
  
  <pre><code>    public class testActivity extends FragmentActivity {
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_pager_adapter);
              initialisePaging();
          }
  
          private  void initialisePaging() {
              List&lt;Fragment&gt; fragments = new Vector&lt;Fragment&gt;();
              fragments.add(Fragment.instantiate(this,fragment1.class.getName()));
              fragments.add(Fragment.instantiate(this,fragment2.class.getName()));
              fragments.add(Fragment.instantiate(this,fragment3.class.getName()));
              PagerAdapter mPagerAdapter = new PagerAdapter(this.getSupportFragmentManager(), fragments);
          Collections.shuffle(fragments, new Random(System.nanoTime()));
  
              ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
              pager.setAdapter(mPagerAdapter);
  
          }
  
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              getMenuInflater().inflate(R.menu.menu_test, menu);
              return true;
          }
  
          @Override
          public boolean onOptionsItemSelected(MenuItem item) {
              int id = item.getItemId();
  
              //noinspection SimplifiableIfStatement
              if (id == R.id.action_settings) {
                  return true;
              }
  
              return super.onOptionsItemSelected(item);
          }
  
      }
  </code></pre>