unable to correctly define edittexts in java <p>I am trying to define 3 edittexts adjacent to each other in java. </p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // LinearLayout mainLayout=(LinearLayout)findViewById(R.id.linearLayout); // LinearLayout -&gt; RelativeLayout main=new RelativeLayout(this); mainParams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ); main.setLayoutParams(mainParams); mainLayout.addView(main); // LinearLayout -&gt; RelativeLayout -&gt; EditText1 EditText item1=new EditText(this); item1.setHint("Enter the item"); item1.setId(5); RelativeLayout.LayoutParams etParams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); etParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); item1.setLayoutParams(etParams); main.addView(item1); // LinearLayout -&gt; RelativeLayout -&gt; EditText2 EditText quantity1=new EditText(this); item1.setHint("Quantity"); item1.setId(6); RelativeLayout.LayoutParams qparams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); etParams.addRule(RelativeLayout.ALIGN_LEFT, 5); item1.setLayoutParams(qparams); main.addView(quantity1); // LinearLayout -&gt; RelativeLayout -&gt; EditText3 EditText rate1=new EditText(this); item1.setHint("rate"); item1.setId(7); RelativeLayout.LayoutParams rparams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); etParams.addRule(RelativeLayout.ALIGN_RIGHT, 6); item1.setLayoutParams(rparams); main.addView(rate1); </code></pre> <p>`</p> <p>I know you might be thinking that i can also do it in xml but the thing is that i have to create more edittexts at runtime.</p> <p>The problem is that all the editTexts are overlapping each other. plz help</p>