title: View layout doesn't refresh on orientation change in android
body: <p>I'd like my VIEW layout to be adjusted on orientation change.</p>
  
  <p>My Manifest is set up with: <code>android:configChanges="keyboardHidden|orientation"</code> on the activity.</p>
  
  <p>I have <code>res/layout-land</code>, <code>res/layout-port</code>.</p>
  
  <p>I have <code>onConfigurationChanged</code> in my <code>Activity</code> (it get's called on rotation).</p>
  
  <p>In my <code>Activity</code> I have a <code>ViewFlipper</code> and inside it I have <code>LinearLayouts</code>.</p>
  
  <p>When I START the <code>Activity</code> in port or land mode, the View's layout is correct (according
  to my <code>res/layout-????</code> files).</p>
  
  <p>But when I'm already in the <code>Activity</code> and I rotate the phone, then my View layout is not changed. The screen is rotated, and the <code>onCreate</code> of the activity is not called, as it's supposed to be, the <code>onConfigurationChanged</code> is called in the <code>Activity</code>, but the screen is always redrawn with the <code>LinearLayout</code> that was loaded when the <code>Activity</code> started.</p>
  
  <p>I have a feeling that I miss out something in the <code>onConfigurationChanged</code>, but don't know what. I guess I need to call some function on the <code>ViewFlipper</code> or on the <code>LinearLayout</code> that's inside. What functions should I call?</p>
  
  <pre><code>ViewFlipper flipper;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      flipper = new ViewFlipper(getApplicationContext());
      setContentView(flipper);
      initLayout();
  }
  
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      setContentView(flipper);
  }
  
  void initLayout() {
      MyView myview = createMyView(0);
      flipper.addView(myview, 0);
      myview = createMyView(1);
      flipper.addView(myview, 1);
      myview = createMyView(1);
      flipper.addView(myview, 1);
  }
  </code></pre>
  
  <p>I tried to add <code>flipper = new ViewFlipper(getApplicationContext());</code> to <code>onConfigurationChanged()</code> but that made everything black after rotation. I guess I'll have to call initLayout, but that would recalculate everything (and that's exactly what I don't want to do, and that's why I'm trying to do it with <code>onConfigurationChanged</code>, as opposed to the android default "dropMyActivity &amp; createANewActivity"</p>
  
  <p><strong>SOLUTION:</strong>
  Previously I thought I can trigger the layout to be refreshed on rotation, but it seems I have to re-create the layout with the current context (after the orientation change)</p>
  
  <pre><code>@Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      setContentView(R.layout.category_flipper);
      ViewFlipper oldFlipper = viewFlipper;
      viewFlipper = (ViewFlipper)findViewById(R.id.categoryFlipper);
      for (int i = 0; i &lt; 3; i++) {
          final CardLayout cl = new CardLayout(this, cardData[i]);
          viewFlipper.addView(cl);
      }
      cardData[viewIndex].restorePlayer();
      viewFlipper.setDisplayedChild(viewIndex);
      oldFlipper.removeAllViews();
  }
  </code></pre>