title: How to access method in fragment from different class?
body: <p>I have <code>navigational drawer</code> and fragment for each drawer item. Now Under each fragment we have created multiple fragments using <code>FragmentPagerAdapter</code>.</p>
  
  <p>I've 3 drawer items as <strong><code>Home</code></strong>, <strong><code>Group</code></strong> and <strong><code>Feedback</code></strong>. Under <strong><code>Home</code></strong>, there are 2 fragments i.e <strong><code>My Profile</code></strong> and <strong><code>Logged</code></strong></p>
  
  <p>so i've created a swipeable tabs for <strong><code>My Profile</code></strong> and <strong><code>Logged</code></strong> and these two fragments are under home item. Now i've to do some network calls in both the fragments(<strong><code>My Profile, Logged</code></strong>) but how to identify which fragment is active on <code>FragmentPagerAdapter</code>? Is it possible to stop adapter to create fragments in advance.</p>
  
  <p><strong><code>HomeFragment</code></strong></p>
  
  <pre><code>        DrawerModel model = new DrawerModel();
          LoggedFragment loggedFrag = new LoggedFragment();
          loggedFrag.setTargetFragment(loggedFrag, 0);
          model.setFragment(loggedFrag);
          dFragments.add(model);
  
          model = new DrawerModel();
          model.setDrawerTitle(getString(R.string.profile_tab_title));
          model.setFragment(new ProfileFragment());
          dFragments.add(model);
  
  
          Bundle bundle = new Bundle();
          bundle.putSerializable("fragments", dFragments);
          fragment = new DrawerFragment();
          fragment.setArguments(bundle);
          navigateFragment(fragment);
  </code></pre>
  
  <p><strong><code>DrawerFragment</code></strong></p>
  
  <pre><code>public class DrawerFragment extends Fragment {
  
  private FragmentAdapter pagerAdapter;
  private ViewPager mViewPager;
  private ArrayList&lt;DrawerModel&gt; fList;
  
  @SuppressWarnings("unchecked")
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      fList = (ArrayList&lt;DrawerModel&gt;) getArguments().getSerializable(
              "fragments");
  
      View v = inflater.inflate(R.layout.swipe_tabs, container, false);
  
      pagerAdapter = new FragmentAdapter(getChildFragmentManager(), fList);
  
      mViewPager = (ViewPager) v.findViewById(R.id.pager);
      mViewPager.setAdapter(pagerAdapter);
  
      return v;
  }
  
  }
  </code></pre>
  
  <p><strong><code>FragmentAdapter</code></strong></p>
  
  <pre><code>public class FragmentAdapter extends FragmentStatePagerAdapter {
  
  private int TOTAL_TABS = 0;
  private ArrayList&lt;DrawerModel&gt; fragmentList;
  private SparseArray&lt;Fragment&gt; mPageReference = new SparseArray&lt;Fragment&gt;();
  
  public FragmentAdapter(FragmentManager fm, ArrayList&lt;DrawerModel&gt; fList) {
      super(fm);
      // TODO Auto-generated constructor stub
      TOTAL_TABS = fList.size();
      fragmentList = fList;
  
  }
  
  @Override
  public Fragment getItem(int position) {
      // TODO Auto-generated method stub
  
      return fragmentList.get(position).getDrawerFragment();
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return TOTAL_TABS;
  }
  
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
      // TODO Auto-generated method stub
      Fragment fragment = (Fragment) super.instantiateItem(container,
              position);
      mPageReference.put(position, fragment);
  
      Log.d("FragmentAdapter - OnCreate", mPageReference.size() + "");
      return fragment;
  }
  
  @Override
  public CharSequence getPageTitle(int position) {
      // TODO Auto-generated method stub
  
      return fragmentList.get(position).getDrawerTitle();
  }
  
  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {
      // TODO Auto-generated method stub
      mPageReference.remove(position);
  
      Log.d("FragmentAdapter - onDestroy", mPageReference.size() + "");
  
      super.destroyItem(container, position, object);
  
  }
  
  public Fragment getFragment(int key) {
      return mPageReference.get(key);
  }
  
  }
  </code></pre>
  
  <p><strong><code>Logged Fragment</code></strong></p>
  
  <pre><code>public class LoggedFragment extends Fragment implements OnClickListener {
  
  TextView tHeader, tEmail, tvPhone;
  SharedPreferences sp;
  ImageView ivAds;
  String bannerUrl = null;
  private Handler handler = new Handler();
  private static final String TAG = "LoggedFragment";
  
  private void addListeners() {
      // TODO Auto-generated method stub
  
      ivAds.setOnClickListener(this);
  
  }
  
  Runnable updateImage = new Runnable() {
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
  
          if (Utility.checkConnectivity(getActivity()))
              new ImageTask((Home_Activity) getActivity(), "Logged")
                      .execute();
  
          handler.postDelayed(this, Utility.AD_DURATION);
      }
  };
  
  @Override
  public void onStart() {
      // TODO Auto-generated method stub
      super.onStart();
  
      if (handler != null)
          handler.post(updateImage);
  
  }
  
  @Override
  public void onStop() {
      // TODO Auto-generated method stub
      super.onStop();
  
      if (handler != null)
          handler.removeCallbacks(updateImage);
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
  
      View v = inflater.inflate(R.layout.logged_in, container, false);
  
      bindComponents(v);
      addListeners();
  
      return v;
  }
  
  private void bindComponents(View v) {
      // TODO Auto-generated method stub
  
      ivAds = (ImageView) v.findViewById(R.id.ivLoggedAds);
  }
  
  public void updateBanner(Bitmap bitmap, String url) {
  
      ivAds.setImageBitmap(bitmap);
      bannerUrl = url;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong><code>Call to update fragment method</code></strong></p>
  
  <pre><code>    Fragment fragment = activity.getSupportFragmentManager()
                      .findFragmentById(R.id.content_frame)
                      .getTargetFragment();
  
              if (fragment instanceof LoggedFragment) {
  
                  LoggedFragment logged = (LoggedFragment) fragment;
                  logged.updateBanner(result, parameter[1]);
  
              } else
                  Log.d(TAG, "No Logged Fragment Found");
  </code></pre>
  
  <p>Now under logged and my profile fragment i need to fetch some data dynamically as soon fragment is visible to user but unable to do so?</p>
  
  <p>Any ideas/suggestions is highly appreciated.</p>