title: Opening different layouts based on values selected in two spinners
body: <p>I am new to android,and in this code i have two spinners and based on the values selected,different layouts should open accordingly. Im stuck with what logic should i use to open different layouts, inside the OnItemSelected for the spinner.Say i have 5 items in spinner and i have 5 different layouts for each item.So how should i do??</p>
  
  <p>Any help or ideas would be much appreciated. Thanks in advance.</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.layout);
      // Spinner element
      Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
      Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
      Button button = (Button) findViewById(R.id.button);
      // Spinner click listener
  
      // Spinner Drop down elements
      List&lt;String&gt; categories = new ArrayList&lt;String&gt;();
      categories.add("Maruti");
      categories.add("Ford");
      categories.add("Nissan");
      categories.add("TATA");
  
      List&lt;String&gt; types = new ArrayList&lt;String&gt;();
      types.add("1Lakh-5Lakh");
      types.add("5Lakh-10Lakh");
      types.add("10Lakh-20Lakh");
      types.add("20Lakh-50Lakh");
      types.add("Above 50Lakhs");
  
      // Creating adapter for spinner
      ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, categories);
      // Drop down layout style - list view with radio button
      dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      ArrayAdapter&lt;String&gt; spinner2Adapter=new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item,types);
      spinner2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      // attaching data adapter to spinner
      spinner1.setAdapter(dataAdapter);
      spinner2.setAdapter(spinner2Adapter);
  
      spinner1.setOnItemSelectedListener(this);
      spinner2.setOnItemSelectedListener(this);
  
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent i=new Intent(SecondActivity.this,ThirdActivity.class);
              startActivity(i);
          }
      });
  }
  
  @Override
  public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
      Spinner spinner1 = (Spinner)parent;
      Spinner spinner2 = (Spinner)parent;
      if(spinner1.equals(position))
      {
  
      }
      if(spinner2.getId() == R.id.spinner2)
      {
  
      }
  
  }
  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
      // TODO Auto-generated method stub
  }}
  </code></pre>