title: Android fragment activity layout not finding view in multi-pane layout with findViewById
body: <p><code>findViewById(R.id.team_detail_container)</code> is failing to find the view. Is my problem with the xml or in the way I am constructing the FragmentActivity? How do I solve this?</p>
  
  <p>To support a customised list for a fragment in the constructor of my fragment activity I have replaced </p>
  
  <p><code>setContentView(R.layout.activity_team_list);</code> </p>
  
  <p>with </p>
  
  <pre><code>frag=(TeamListFragment)getSupportFragmentManager().findFragmentById(android.R.id.content);
          if (frag==null) {
              frag=new TeamListFragment();
              getSupportFragmentManager().beginTransaction().add(android.R.id.content, frag).commit();
  </code></pre>
  
  <p>So that my class now looks like this</p>
  
  <pre><code>public class TeamListActivity extends SherlockFragmentActivity implements
          TeamListFragment.Callbacks {
  
      private boolean mTwoPane;
      private TeamListFragment frag=null;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          frag=(TeamListFragment)getSupportFragmentManager().findFragmentById(android.R.id.content);
          if (frag==null) {
              frag=new TeamListFragment();
              getSupportFragmentManager().beginTransaction().add(android.R.id.content, frag).commit();
          }
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          if (findViewById(R.id.team_detail_container) != null) {
  
              Log.i("@@@@", "Team Detail Container has been found! Yaay!");
              mTwoPane = true;
              ((TeamListFragment) getSupportFragmentManager().findFragmentById(
                      R.id.team_list)).setActivateOnItemClick(true);
          }   
      }
  </code></pre>
  
  <p>The <code>if (findViewById(R.id.team_detail_container) != null) {</code> condition is never met despite the fact that team_detail_container exists in the xml file that is used</p>
  
  <pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/team_list_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginLeft="16dp"
          android:layout_marginRight="16dp"
          android:orientation="horizontal"
          android:showDividers="middle"
          tools:context=".TeamListActivity" &gt;
  
          &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/team_list"
                  android:orientation="vertical"
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:paddingLeft="8dp"
                  android:paddingRight="8dp"&gt;
  
              &lt;ListView
                  android:id="@android:id/list"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:drawSelectorOnTop="false" /&gt;
  
              &lt;TextView android:id="@id/android:empty"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="No data"/&gt;
           &lt;/LinearLayout&gt;        
          &lt;View
              android:layout_width="fill_parent"
              android:layout_height="1dp"
              android:background="?android:attr/listDivider"
          /&gt; 
  
          &lt;FrameLayout
              android:id="@+id/team_detail_container"
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="3" /&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I know that this particular layout xml is being used as changes I make to the xml file are reflected in the app.
  I also know that the condition is never met as I never get the log message <code>Log.i("@@@@", "Team Detail Container has been found! Yaay!");</code> and the behaviour  get is that when an item is selected the list view is replaced with the detail fragments instead of the detail fragments being displayed next to the list view because the item selected conditions are not being met</p>
  
  <pre><code>@Override
  public void onItemSelected(int id) {
      if (mTwoPane) {
                  // mTwoPane is never set! Why?
  
          Bundle arguments = new Bundle();
          arguments.putInt(TeamDetailFragment.ARG_ITEM_ID, id);
          TeamDetailFragment fragment = new TeamDetailFragment();
          fragment.setArguments(arguments);
          getSupportFragmentManager().beginTransaction()
                  .replace(R.id.team_detail_container, fragment).commit();
  
      } else {
          // In single-pane mode, simply start the detail activity
          // for the selected item ID.
          Intent detailIntent = new Intent(this, TeamDetailSwipeActivity.class);
          detailIntent.putExtra(TeamDetailFragment.ARG_ITEM_ID, id);
          startActivity(detailIntent);
      }
  }
  </code></pre>