title: Layout alignment of spinner and TextView in LinearLayout programmatically android
body: <p>I want to achieve this layout below as shown in the image below...<strong>example -spinner1 then text1  then new line spinner2 then text2 and so on</strong>....every thing is fine I just want to arrange the layout correctly..I attached both the images with I want and which is currently showing with the code.</p>
  
  <p>I want layout like this below image</p>
  
  <p><a href="https://i.stack.imgur.com/byzFo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/byzFo.png" alt="enter image description here"></a></p>
  
  <p>but currently its showing like this below-</p>
  
  <p><a href="https://i.stack.imgur.com/55qxG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/55qxG.png" alt="enter image description here"></a></p>
  
  <p><strong>Bookdetails.java</strong></p>
  
  <pre><code>public class Bookdetails extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.bookdetails);
  
  
          final ArrayList&lt;String&gt; spinnerArray = new ArrayList&lt;String&gt;();
          spinnerArray.add("Yes");
          spinnerArray.add("No");
  
  
          final String seat1 = getIntent().getExtras().getString("seat1");
          final String seat2 = getIntent().getExtras().getString("seat2");
          final String seat3 = getIntent().getExtras().getString("seat3");
          final String seat4 = getIntent().getExtras().getString("seat4");
          final String seat5 = getIntent().getExtras().getString("seat5");
          final String seat6 = getIntent().getExtras().getString("seat6");
          Log.i("seats", seat1+seat2+seat3+seat4+seat5+seat6);
          Toast toast = Toast.makeText(this, seat1+seat2+seat3+seat4+seat5+seat6, Toast.LENGTH_LONG);
          toast.show();
  
          final int N = 6; 
  
          final TextView[] myTextViews = new TextView[N]; 
          LinearLayout ll = (LinearLayout) findViewById(R.id.layout);
          //setContentView(ll);
          if(!(seat1==null)){
              final TextView rowTextView = new TextView(this);
              rowTextView.setText("Seat selected" + seat1);
              ll.addView(rowTextView);
  
              //&lt;------------------------------------------------------------------------------&gt;
              Spinner spinner = new Spinner(this);
              ArrayAdapter&lt;String&gt; spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
              spinner.setAdapter(spinnerArrayAdapter);
              spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
  
                  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                          int arg2, long arg3) {
                      // TODO Auto-generated method stub
  
                      Toast.makeText(getBaseContext(), spinnerArray.get(arg2).toString()+""+seat1, 
                              Toast.LENGTH_SHORT).show();
                  }
  
                  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                      // TODO Auto-generated method stub
  
                  }
              });
              ll.addView(spinner);
  
              //&lt;------------------------------------------------------------------------------&gt;
          }
          if(!(seat2==null)){
              final TextView rowTextView = new TextView(this);
              rowTextView.setText("Seat selected" + seat2);
              ll.addView(rowTextView);
              //&lt;------------------------------------------------------------------------------&gt;
              Spinner spinner = new Spinner(this);
              ArrayAdapter&lt;String&gt; spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
              spinner.setAdapter(spinnerArrayAdapter);
              spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
  
                  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                          int arg2, long arg3) {
                      // TODO Auto-generated method stub
  
                      Toast.makeText(getBaseContext(), spinnerArray.get(arg2).toString()+""+seat2, 
                              Toast.LENGTH_SHORT).show();
                  }
  
                  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                      // TODO Auto-generated method stub
  
                  }
              });
              ll.addView(spinner);
  
              //&lt;------------------------------------------------------------------------------&gt;
  
          }
          if(!(seat3==null)){
              final TextView rowTextView = new TextView(this);
              rowTextView.setText("Seat selected" + seat3 );
              ll.addView(rowTextView);
              //&lt;------------------------------------------------------------------------------&gt;
              Spinner spinner = new Spinner(this);
              ArrayAdapter&lt;String&gt; spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
              spinner.setAdapter(spinnerArrayAdapter);
              spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
  
                  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                          int arg2, long arg3) {
                      // TODO Auto-generated method stub
  
                      Toast.makeText(getBaseContext(), spinnerArray.get(arg2).toString()+""+seat3, 
                              Toast.LENGTH_SHORT).show();
                  }
  
                  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                      // TODO Auto-generated method stub
  
                  }
              });
              ll.addView(spinner);
  
              //&lt;------------------------------------------------------------------------------&gt;
          }
          if(!(seat4==null)){
              final TextView rowTextView = new TextView(this);
              rowTextView.setText("Seat selected"+ seat4  );
              ll.addView(rowTextView);
              //&lt;------------------------------------------------------------------------------&gt;
              Spinner spinner = new Spinner(this);
              ArrayAdapter&lt;String&gt; spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
              spinner.setAdapter(spinnerArrayAdapter);
              spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
  
                  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                          int arg2, long arg3) {
                      // TODO Auto-generated method stub
  
                      Toast.makeText(getBaseContext(), spinnerArray.get(arg2).toString()+""+seat4, 
                              Toast.LENGTH_SHORT).show();
                  }
  
                  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                      // TODO Auto-generated method stub
  
                  }
              });
              ll.addView(spinner);
  
              //&lt;------------------------------------------------------------------------------&gt;
          }
          if(!(seat5==null)){
              final TextView rowTextView = new TextView(this);
              rowTextView.setText("Seat selected"+ seat5  );
              ll.addView(rowTextView);
              //&lt;------------------------------------------------------------------------------&gt;
              Spinner spinner = new Spinner(this);
              ArrayAdapter&lt;String&gt; spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
              spinner.setAdapter(spinnerArrayAdapter);
              spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
  
                  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                          int arg2, long arg3) {
                      // TODO Auto-generated method stub
  
                      Toast.makeText(getBaseContext(), spinnerArray.get(arg2).toString()+""+seat5, 
                              Toast.LENGTH_SHORT).show();
                  }
  
                  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                      // TODO Auto-generated method stub
  
                  }
              });
              ll.addView(spinner);
  
              //&lt;------------------------------------------------------------------------------&gt;
          }
          if(!(seat6==null)){
              final TextView rowTextView = new TextView(this);
              rowTextView.setText("Seat selected"+ seat6  );
              ll.addView(rowTextView);
              //&lt;------------------------------------------------------------------------------&gt;
              Spinner spinner = new Spinner(this);
              ArrayAdapter&lt;String&gt; spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
              spinner.setAdapter(spinnerArrayAdapter);
              spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
  
                  public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                          int arg2, long arg3) {
                      // TODO Auto-generated method stub
  
                      Toast.makeText(getBaseContext(), spinnerArray.get(arg2).toString()+""+seat6, 
                              Toast.LENGTH_SHORT).show();
                  }
  
                  public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                      // TODO Auto-generated method stub
  
                  }
              });
              ll.addView(spinner);
  
              //&lt;------------------------------------------------------------------------------&gt;
          }
  
      }
  }
  </code></pre>
  
  <p><strong>bookdetails.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
  
      &lt;LinearLayout
          android:id="@+id/layout"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical" &gt;
  
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>