title: Why is my Fragments not hidden when I set the hide/show
body: <p><strong>UPDATE</strong> <strong>added my own answer since I solved it. The question is untouched look at answer!</strong>    </p>
  
  <p>I was following this <a href="http://www.android4devs.com/2015/06/navigation-view-material-design-support.html" rel="nofollow">Navigation View - Material Design Support Library Tutorial</a>. I made some changes so that i could hide and show the <code>Fragments</code>. The <code>Fragment</code> will synk against FireBase so I want them to be alive and well, and not constantly recreated. The problem is that I can never make them hide. I clearly see in the <strong>LogCat</strong> that <code>Fragment</code> <code>onAttach()</code>, with is a requirement for show/hide to work right??
  What am I completely missing here?</p>
  
  <p>Adding some code first AppCompatActivity </p>
  
  <pre><code>/**
   * Main launcher
   */
  public class FragmentActivityMain extends ManagedAppCompatActivity implements OnClickListener,
          ConfirmDialogListener, NotificationDialogListener, OnConnectionStateListener,
          NavigationView.OnNavigationItemSelectedListener {
  
      private static final String TAG = FragmentActivityMain.class.getName();
  ............
  </code></pre>
  
  <p>This is the TypedArray holding NavigationView menu items(Fragments)</p>
  
  <pre><code>    &lt;!-- NavigationView items --&gt;
      &lt;string-array name="navigationview_items"&gt;
          &lt;item&gt;com.port.android.ui.HomeFragment&lt;/item&gt;
          &lt;item&gt;com.port.android.ui.ChatFragment&lt;/item&gt;
          &lt;item&gt;com.port.android.ui.BillboardFragment&lt;/item&gt;
          &lt;item&gt;com.port.android.ui.NewsFragment&lt;/item&gt;
          &lt;item&gt;com.port.android.ui.settingsFragment&lt;/item&gt;
          &lt;item&gt;com.port.android.ui.LoginFragment&lt;/item&gt;
      &lt;/string-array&gt;
  </code></pre>
  
  <p>Loading the TypedArray</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  ...
  navigationviewItems = getResources().obtainTypedArray(R.array.navigationview_items);
  
  }
  </code></pre>
  
  <p>The onNavigationItemSelected listener that will check if the Fragment is added to the supportFragmentManager and if not adding it</p>
  
  <pre><code>    // This method will trigger on item Click of navigation menu
  @Override
  public boolean onNavigationItemSelected(MenuItem menuItem) {
      String tag;
      //Closing drawer on item click
      drawerLayout.closeDrawers();
      View r = findViewById(R.id.landing_page);
      //Check to see which item was being clicked and perform appropriate action
      switch (menuItem.getItemId()) {
          case R.id.home: // HomeFragment
              tag = navigationviewItems.getString(0);
              if (fragmentManager.findFragmentByTag(tag) == null) {
                  try {
                      fragmentManager.beginTransaction().add(R.id.frame, (Fragment) Class.forName(tag).newInstance(), tag)
                              .addToBackStack(tag)
                              .commit();
                      MyLog.i(TAG, "Class.forName(tag) = " + tag);
                  } catch (InstantiationException e) {
                      e.printStackTrace();
                  } catch (IllegalAccessException e) {
                      e.printStackTrace();
                  } catch (ClassNotFoundException e) {
                      e.printStackTrace();
                  }
              } else
                  MyLog.i(TAG, "switch SHOW " + tag);
              hideAllFrags(tag);
              return true;
          case R.id.chat: // ChatFragment
              tag = navigationviewItems.getString(1);
              ....................
  </code></pre>
  
  <p>When the above onNavigationItemSelected has selected the Fragment to be visible this method should hide all Fragments except @param fragment.</p>
  
  <pre><code>/**
   * Hide all Fragments except @param fragment
   */
  private void hideAllFrags(String fragment) {
      for (int index = 0; index &lt; navigationviewItems.length(); index++)
          try {
              if (!fragment.equals(navigationviewItems.getString(index))) {
                  if (fragmentManager.findFragmentByTag(fragment) != null)
                      fragmentManager.beginTransaction().hide(fragmentManager.findFragmentByTag(fragment)).commit();
                  Log.d(TAG, "HIDING " + navigationviewItems.getString(index));
              }else{
                  if (fragmentManager.findFragmentByTag(fragment) != null)
                      fragmentManager.beginTransaction().show(fragmentManager.findFragmentByTag(fragment)).commit();
                  Log.d(TAG, "SHOWING " + navigationviewItems.getString(index));
  
              }
          } catch (Exception e) {
              Log.d(TAG, "CANNOT LOAD navigationviewItems " + navigationviewItems.getString(index));
              throw new RuntimeException(e);
          }
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/jdFNC.jpg" rel="nofollow">This is what it looks like and both the chat and the home fragment are visible</a></p>