title: Call a fragment public void from the parent activity
body: <p>I am working on the BitMapFun project.
  I am trying to call a fragment public void from the parent activity of the fragment.</p>
  
  <p>Some source code :</p>
  
  <p>Activity :</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      if (BuildConfig.DEBUG) {
          Utils.enableStrictMode();
      }
      super.onCreate(savedInstanceState);
      setContentView(R.layout.image_detail_pager);
  
      // Fetch screen height and width, to use as our max size when loading images as this
      // activity runs full screen
      final DisplayMetrics displayMetrics = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
      final int height = displayMetrics.heightPixels;
      final int width = displayMetrics.widthPixels;
  
      ImageCache.ImageCacheParams cacheParams =
              new ImageCache.ImageCacheParams(this, IMAGE_CACHE_DIR);
      cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of app memory
  
      // The ImageFetcher takes care of loading images into our ImageView children asynchronously
      mImageFetcher = new ImageFetcher(this, longest);
      mImageFetcher.addImageCache(getSupportFragmentManager(), cacheParams);
      mImageFetcher.setImageFadeIn(false);
  
      // Set up ViewPager and backing adapter
      mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), Images.imageUrls.length);
      mPager = (ViewPager) findViewById(R.id.pager);
      mPager.setAdapter(mAdapter);
      mPager.setOffscreenPageLimit(2);
  
      // Set up activity to go full screen
      getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
  
      // Enable some additional newer visibility and ActionBar features to create a more immersive photo viewing experience
      if (Utils.hasHoneycomb()) {
          final ActionBar actionBar = getActionBar();
  
          // Set home as up
          actionBar.setDisplayHomeAsUpEnabled(true);
          actionBar.setTitle("");
  
          // Start low profile mode
          mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
          // actionBar.hide();
      }
  
      // Set the current item based on the extra passed in to this activity
      final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1);
      if (extraCurrentItem != -1) {
          mPager.setCurrentItem(extraCurrentItem);
      }
  
      // Événement changement d'image
      mPager.setOnPageChangeListener(new OnPageChangeListener() {
          @Override
          public void onPageSelected(int arg0) {
              // cache le bouton de retour situé dans le coin supérieur gauche si l'utilisateur change d'image
              mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
          }
  
          @Override
          public void onPageScrollStateChanged(int arg0) { }
  
          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) { }
       });
  }
  
  (...)
  
  ImageDetailFragment.SetPhotoView();
  
  (...)
  
  
  private class ImagePagerAdapter extends FragmentStatePagerAdapter {
      private final int mSize;
  
      public ImagePagerAdapter(FragmentManager fm, int size) {
          super(fm);
          mSize = size;
      }
  
      @Override
      public int getCount() {
          return mSize;
      }
  
      @Override
      public Fragment getItem(int position) {
          return ImageDetailFragment.newInstance(Images.imageUrls[position]);
      }
  }
  </code></pre>
  
  <p>Fragment :</p>
  
  <pre><code>private ImageView mImageView;
  
  (...)
  
      public void SetPhotoView() {
          mAttacher = new PhotoViewAttacher(mImageView);
      }
  </code></pre>
  
  <p>Layout file of detailfragment :</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
  
      &lt;ProgressBar
          style="?android:attr/progressBarStyleLarge"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center" /&gt;
  
      &lt;biz.jchambon.gedm.bitmapfun.ui.RecyclingImageView
          android:id="@+id/imageView"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:contentDescription="@string/imageview_description" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>And layout_detail_pager.xml :</p>
  
  <pre><code>&lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/pager"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
  
  &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>
  
  <p>The problem is I can't make a static reference to the non-static method SetPhotoView() ...
  If I change SetPhotoView to a static method, I have to change mImageView to be static too, and my fragment is not working anymore.</p>
  
  <p>Edit:</p>
  
  <p>If I use 
  ImageDetailFragment fragment = (ImageDetailFragment)getSupportFragmentManager().findFragmentById(mPager.getId());
  fragment.SetPhotoView();</p>
  
  <p>Then it works but with the wrong fragment ...
  How can I find the ID of the actual fragment ?</p>
  
  <p>In fact, I have the same problem as here : <a href="https://stackoverflow.com/questions/18609261/getting-the-current-fragment-instance-in-the-viewpager">Getting the current Fragment instance in the viewpager</a>
  But for me, findFragmentByTag("android:switcher:" + R.id.pager + ":" + mPager.getCurrentItem()) return nothing :/</p>
  
  <p>Someone could tell me how can I get around this ??</p>