title: Change layout using a spinner in Android
body: <p>I'm trying to change the layout of my activity according to my selection inside the spinner.
  But after the first selection, the spinner become white and I'm not able to decide another selection.
  The code I'm using is the following:</p>
  
  <pre><code>public class MainActivity extends Activity implements OnItemSelectedListener {
  
  Spinner spinner;
  String[] options = { "Modulo1", "Modulo2" };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      spinner = (Spinner) findViewById(R.id.spinner);
      ArrayAdapter&lt;String&gt; adapter_state = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_spinner_item, options);
      adapter_state
              .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner.setAdapter(adapter_state);
      spinner.setOnItemSelectedListener(this);
  
  }
  
  int check = 0;
  
  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position,
          long id) {
      check = check + 1;
      if (check &gt; 1) {
          int selState = spinner.getSelectedItemPosition();
          switch (selState) {
          case 0:
              setContentView(R.layout.activity_main);
  
              break;
          case 1:
              setContentView(R.layout.activity2_main);
  
              break;
  
          }
  
      }
  }
  
  @Override
  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
      // TODO Auto-generated method stub
  
  }
  
  //
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Any suggestion?
  Thanks</p>