title: Fragment Adapter AlertDialog findFragmentByTag returns null on phone
body: <p>I'm doing a typical fragment activity with the left pane, Fragment A, as a list and the right pane, Fragment B as the content (on a tablet), and on the phone both are in one pane.</p>
  
  <p>Everything works great on the tablet version. But on the phone version I run into a problem. My Fragment B consists of some TextViews and below them, a GridView. I'd like to update the TextViews every time the user clicks on a grid item. This works fine. The problem is in implementing an AlertDialog within the grid adapter:</p>
  
  <pre><code>OnClickListener clickListener = new OnClickListener() {
      @Override
      public void onClick(View v) {
          AlertDialog.Builder builder = new AlertDialog.Builder(mContext.getContext());               
          ...             
          builder.setPositiveButton(mContext.getContext().getResources().getString(
              R.string.ok),  new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
  
                      fragActivity.getSupportFragmentManager().executePendingTransactions();
  
                      FragmentB f = (FragmentB)
                          ((MyActivity) fragActivity).getSupportFragmentManager()
                          .findFragmentByTag(FragmentB.TAG);
  
                      item.setAmount(helperDouble);  //shouldn't be relevant to the problem
                      if (f != null) {
                          Log.i("GridAdapter", "f is not null, updating views");
                          f.updateViews();                                    
                      } else {
                          Log.i("GridAdapter", "f is null, what the...");
                      }
                  }
              }
          });
  
          AlertDialog dialog = builder.create();
          dialog.show();
      }
  };
  </code></pre>
  
  <p>FragmentB f returns fine every time on the tablet, but no matter what I seem to do, it always returns null on the phone. It seems similar to <a href="https://stackoverflow.com/questions/9966928/finding-fragment-view-on-activity-android-findfragmentbytagstring-tag-returns">this SO post</a> but I don't know if I can apply that to my situation. Here's how I add the fragment in MyActivity:</p>
  
  <pre><code>@Override
  public void onCustomerSelected(Customer customer, int index) {
      //update fragment here
  
      if (isScreenSizeLarge()) {  //if tablet:
          FragmentB f;
          //if fragment doesn't exist, create it
          if (getSupportFragmentManager().findFragmentByTag(FragmentB.TAG) == null) {
              f = FragmentB.newInstance(customer, index);
              FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
              trans.add(R.id.fragment_b_container, f, FragmentB.TAG);
              trans.commit();
              getSupportFragmentManager().executePendingTransactions();
          } else {
              f = (FragmentB) getSupportFragmentManager()
                  .findFragmentByTag(FragmentB.TAG);
          }
      } else {       //if phone:
          FragmentB newCartFrag = FragmentB.newInstance(customer, index);
          FragmentTransaction newTrans = getSupportFragmentManager().beginTransaction();
          newTrans.replace(R.id.fragment_container, newCartFrag);
          newTrans.addToBackStack(FragmentB.TAG);
          newTrans.commit();
          getSupportFragmentManager().executePendingTransactions();
      }
  }
  </code></pre>
  
  <p>(Yes I'm aware I called executePendingTransactions() twice, I did just in case.) </p>
  
  <p>So I'm assuming the problem has something to do with the fragment (or fragment activity) "losing focus" of the fragment. I just don't understand the difference between why it would find it on the tablet (which could lose focus because it has two fragments to worry about) but not the phone (wherein FragmentB is the only active fragment at the time).</p>