title: Adding EditText to LinearLayout programmatically in Android
body: <p>I can't make my <code>EditTexts</code> to fit in <code>LinearLayout</code> side by side sharing the same amout of space.</p>
  
  <p>Here is the code that does it:</p>
  
  <pre><code>LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  
  @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          textFieldsLayout = (LinearLayout) findViewById(R.id.LinearLayout2);
  
          for(int i=1; i &lt;= 8; i++){
  
              final EditText ed = new EditText(this);
  
              ed.setText("" + i);
  
              ed.setInputType(2);
  
              ed.setLayoutParams(lparams);
  
              textFieldsLayout.addView(ed);
          }   
      }
  </code></pre>
  
  <p>this code manages to add <code>EditText</code> to my layout but they appear side by side, and there is empty space at the end of <code>LinearLayout</code>, when I change params to <code>WRAP_CONTENT</code>, only first <code>EditText</code> added to layout fills the layout and others don't appear there, any idea what am I doing wrong here?</p>