title: Change Activity contents based on options of a spinner?
body: <p>I am quite new to android. I want to change activity contents based on the selected option from a spinner. for example i have two options in a spinner "Option2" and "Option2" and two date pickers. I want my activity to work this way that when i select option 1 i should see one date picker and when i select option 2 i see two date pickers dynamically.</p>
  
  <p>Here is my code for spinner</p>
  
  <pre><code>Spinner spinner= (Spinner) findViewById(R.id.spinner);
  final List&lt;String&gt; List=new ArrayList&lt;String&gt;();
      List.add("Option1");
      List.add("Option2");
  
  ArrayAdapter&lt;String&gt; Adapter=new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_1,List);
      Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      triptype.setAdapter(Adapter);
  spinner.setOnItemSelectedListener(new OnItemSelectedListener()
      {
              @Override
          public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                  int position, long id) {
              // TODO Auto-generated method stub
              int pos1=position;
              selectedOption=spinner.getSelectedItem().toString();
  
              prefs = getSharedPreferences(prefName, MODE_PRIVATE);
              SharedPreferences.Editor editor = prefs.edit();
  
              //---save the values in the EditText view to preferences---
              editor.putInt("index", pos1);
              editor.putString("value", selectedoption);
  
              //---saves the values---
              editor.commit();
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
              // TODO Auto-generated method stub
  
          }
  
      });
  </code></pre>