title: Single-pane to Two-pane
body: <p>I'm working on a Android project and got a problem with the two-pane layout (list + detail).</p>
  
  <p>Current state:</p>
  
  <ul>
  <li>Working two-pane layout (like in GMail-App) for screens with larger width than 600dp and landscape orientation.</li>
  <li>Switching from two-pane to single-pane layout works</li>
  <li>Working single-pane layout for devices with smaller width than 600dp in any orientation.</li>
  </ul>
  
  <p>Problem:</p>
  
  <p>If the user(device screen width larger than 600dp) is in portrait-mode and selects a list item the detail view popups up (which is correct). If the user now changes orientation to landscape the layout should change to two-pane layout with the list and the selected detail view. But the app stays in the single-pane layout. </p>
  
  <p>In my opinion the problem is caused because I start a new activity in single-pane mode instead of exchanging some fragments. But i really don't know how to achieve this.</p>
  
  <p>The following code shows what happens if the user selects a list item.</p>
  
  <pre><code>@Override
  public void onItemSelected(AndroidCalendar calendar) {
      if (mTwoPane) {
          // two-pane mode
          Bundle arguments = new Bundle();
          arguments.putSerializable(CalendarDetailFragment.CALENDAR, calendar);
          CalendarDetailFragment fragment = new CalendarDetailFragment();
          fragment.setArguments(arguments);
          getFragmentManager().beginTransaction()
                  .replace(R.id.calendaritem_detail_container, fragment)
                  .commit();
  
      } else {
          // single-pane mode
          Intent detailIntent = new Intent(this, CalendarDetailActivity.class);
          detailIntent.putExtra(CalendarDetailFragment.CALENDAR, calendar);
          startActivity(detailIntent);
      }
  </code></pre>
  
  <p>For example the Boxer app (EMail) and gReader supports this behavior. I think GMail app too.</p>