title: Fragment methods are not getting called
body: <p>I have implemented <strong>Navigation drawer</strong> given in the <code>Android Studio 1.5.1</code>.</p>
  
  <ul>
  <li>I have 5 navigation drawer items with a fragment to each of them. Each Fragment has Share method (Not common).</li>
  <li>Inside 1st Navigation drawer item's fragment lets say <strong>OldStory Fragment</strong>, I am having Swipe view with Viewpager consisting  3 fragments with FragmentStatePagerAdapter. It has Share method.</li>
  </ul>
  
  <p><strong>Problem</strong>
   - Share Method from <strong>Story Fragment</strong> is getting called every time even when other fragment is shown on screen. After debugging I came to know that method from <strong>Story</strong> fragment is getting called.
   - If I disable OldStory Fragment then everything works fine.</p>
  
  <p>I am unable to solve this problem. I read so many Question/answers but they are related to Activity and Fragment methods. Please help me to solve this problem.</p>
  
  <p><strong>Note</strong> - <strong>OldStory</strong> fragment has inner class that extends FragmentStatePagerAdapter class. This class creates Many <strong>Story Fragments</strong>. Other implementation is same.</p>
  
  <pre><code>public class OldStory extends Fragment {
  
  private StoryPagerAdapter storyPagerAdapter;
  private InfiniteViewPager viewPager;
  SharedPreferences sharedPreferences;
  private int TotalCount;
  
  public OldStory() {
      // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      // Notify the system to allow an options menu for this fragment.
  
  }
  
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      final View rootView = inflater.inflate(R.layout.fragment_old_story, container, false);
      viewPager = (InfiniteViewPager) rootView.findViewById(R.id.pager);
      viewPager.setOffscreenPageLimit(0);
      sharedPreferences = getActivity().getSharedPreferences(Startup.PreferenceSETTINGS, Context.MODE_PRIVATE);
      TotalCount = sharedPreferences.getInt(Startup.StoryCount, 4);
      storyPagerAdapter = new StoryPagerAdapter(getFragmentManager());
      PagerAdapter wrappedAdapter = new InfinitePagerAdapter(storyPagerAdapter);
      viewPager.setAdapter(wrappedAdapter);
      viewPager.setCurrentItem(TotalCount-1);
  
      return rootView;
  }
  
  public class StoryPagerAdapter extends FragmentStatePagerAdapter {
      public StoryPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
  
          return Story.newInstance(position+1);
      }
  
      @Override
      public int getCount() {
          return TotalCount;
      }
  }
  }
  </code></pre>
  
  <p><strong>Story Fragment</strong> method Implementation - </p>
  
  <pre><code>@Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  
      menu.clear();
      inflater.inflate(R.menu.story, menu);
      getActivity().getMenuInflater().inflate(R.menu.main, menu);
  }
  
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.Refresh:
              // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator
              if(!visiblity) {
                  if (!RefreshLayout.isRefreshing()) {
                      ErrorLayout.setVisibility(View.GONE);
                      RefreshLayout.setRefreshing(true);
                  }
  
                  // Start our refresh background task
                  initiateRequest(Today);
              }
              return true;
  
          case R.id.Share:
              //InShort = sharedPreferences.getString(Startup.InShort, null);
              Toast.makeText(getContext(), "Stories", Toast.LENGTH_SHORT).show();
              if (InShort!= null &amp;&amp; !InShort.isEmpty())
              {
  
                  Intent sendIntent = new Intent(Intent.ACTION_SEND);
                  sendIntent.putExtra(Intent.EXTRA_TEXT, "Hi From Story");
                  sendIntent.setType("text/plain");
                  startActivity(sendIntent);
              }
  
              return true;
  
          default:
              return super.onOptionsItemSelected(item);
      }
  
  
  }
  </code></pre>
  
  <p><strong>MainActivity</strong> used for switching fragments.</p>
  
  <pre><code>public boolean onNavigationItemSelected(MenuItem item) {
      // Handle navigation view item clicks here.
      displayView(item.getItemId());
  
      return true;
  }
  
  //method to replace Views in ID = content_frame in content_main
  public void displayView(int viewID)
  {
      fragment = null;
      title = getString(R.string.app_name);
  
      switch (viewID)
      {
          case R.id.nav_frag0:
              fragment = new OldStory();
              title = getString(R.string.story);
              viewIsAtHome = true;
              break;
  
          case R.id.nav_frag1:
              fragment = new Fragment1();
              title = getString(R.string.fragment1);
              viewIsAtHome = false;
              break;
  
          case R.id.nav_frag2:
              fragment = new Fragment2();
              title = getString(R.string.fragment2);
              viewIsAtHome = false;
              break;
  
          case R.id.nav_frag3:
              fragment = new Fragment3();
              title = getString(R.string.fragment3);
              viewIsAtHome = false;
              break;
  
          case R.id.nav_frag4:
              fragment = new Fragment4();
              viewIsAtHome = false;
              title = getString(R.string.fragment4);
              break;
  
          case R.id.nav_share:
              fragment = new Fragment5();
              title = getString(R.string.fragment5);
              viewIsAtHome = false;
              break;
  
      }
  
      if (fragment != null)
      {
          FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
          ft.replace(R.id.content_frame,fragment);
          ft.commit();
      }
  
      //set the toolbar title
      if(getSupportActionBar() != null)
      {
          getSupportActionBar().setTitle(title);
      }
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      drawer.closeDrawer(GravityCompat.START);
  }
  </code></pre>